[Python-ideas] Changing semantics of for-loop variable

Terry Reedy tjreedy at udel.edu
Fri Sep 30 07:06:31 CEST 2011


On 9/29/2011 5:31 PM, Greg Ewing wrote:
> Guido has asked me to start a new thread for discussing
> this idea.
>
> To recap, instead of trying to come up with some new
> sugar to make the default-argument hack taste slightly
> less bitter, I suggest making a small change to the
> semantics of for-loops:
>
> If the loop variable is referenced from an inner scope,
> instead of replacing the contents of its cell, create
> a *new* cell on each iteration.

Since loop variables do not normally have cells, I really do not 
understand from this what you are proposing. What I do understand is 
that you would have the content of the body of a loop change the 
behavior of the loop. This is a radical change with what to me is little 
practical justification and not a 'small change'.

I have used about 20 languages and in all of them, a 'variable' refers 
to a specific memory block or or name. You must have a very different 
background to think that doing something else is normal.

> Code following the loop would then continue to see the
> last value bound to the loop variable, as now, but
> inner functions would capture different versions of
> it.
>


-- 
Terry Jan Reedy




More information about the Python-ideas mailing list