[Python-Dev] Visibility scope for "for/while/if" statements

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Sep 23 03:53:27 CEST 2005


Josiah Carlson wrote:

> As for list comprehensions, they were literally meant to be a
> completely equivalent translation of a set of for loops.

I don't think that's quite true. I doubt whether anyone
really thought about the issue when LCs were first being
discussed. I didn't, but if I had, I wouldn't have
considered the variable-leaking as being something that
it was necessary to preserve, because the only use case
for it is something you can't do with an LC anyway.

The reasons for the variable-leaking being preserved are
(1) it fell out of the implementation and (2) it makes the
documentation slightly simpler, since LCs can be described
fully and accurately in terms of translation to for-loops.

Whether those are *good* reasons or not is debatable.

In Py3k it's possible that this will be resolved by making
for-loop variables local to the loop as well. Or maybe not.

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+


More information about the Python-Dev mailing list