Towards faster Python implementations - theory

Hendrik van Rooyen mail at microcorp.co.za
Thu May 10 03:44:29 EDT 2007


"Terry Reedy" <t..y at u,,.edu> wrote:

> "Hendrik van Rooyen" <mail at microcorp.co.za> wrote in message 
> news:013d01c79210$5e441280$03000080 at hendrik...
> | I am relatively new on this turf, and from what I have seen so far, it
> | would not bother me at all to tie a name's type to its first use, so that
> | the name can only be bound to objects of the same type as the type
> | of the object that it was originally bound to.
> |
> | But maybe I am missing the point of dynamism.
> |
> | Would an implementation of the above break lots of stuff in practice?
> 
> For function local variables, if you mean 'originally bound to' in the 
> current call invocation, that would sometimes be ok (and that is sort of 
> what Psycho does).  But if you mean in the original binding in the first 
> call invocation, then that would cripple many functions.
> 
Errr - I was thinking a bit simplistic - I know I can write:

def f(x):
  for y in x:
    print y    # using print here as short for doing something complicated

And that would currently "work" with any iterable, as x could 
currently be anything.

It seems that such functions are the problem, as something like this:

x = [1,2,3,4,5]
for y in x:
  print y

does not have the same hassle for x, but can shift the problem to y:

x = [1,2,3,4,(1,2)]
for y in x:
  print y

I can't see an easy way to put the patient back into his straight jacket.

Makes you want to use pre defined globals...

- Hendrik




More information about the Python-list mailing list