Lisp-likeness

Greg Ewing greg at cosc.canterbury.ac.nz
Thu Mar 17 03:24:56 CET 2005


Michele Simionato wrote:

> However this approach has a drawback (which is not there in Scheme,
> since Scheme has set!): if a new scope was created at each iteration
> (which is what the function call is doing) we could not reassign
> variables (i.e. they would become names locals to the "for" scope,
> touching them would not affect variables outside the scope).

There is a middle way: the for-loop could be made
to create a new binding for its control variable
on each iteration, while the body continues to
execute in the outer scope as before.

It would actually be very easy to implement this
in CPython the way it currently works. Guido seems
to be against this sort of thing, though, as he
seems to regard it as a useful feature that the
for-loop control variable is not local to the
loop.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list