[Python-Dev] Possible resolution of generator expression variablecapture dilemma (original) (raw)

Tim Peters tim.one at comcast.net
Thu Mar 25 00:13:47 EST 2004


[Guido]

If I had known Scheme 15 years ago I might have considered this -- ...

Yes, but you would have rejected it in favor of Python's original 3-level scoping then anyway. That was an experiment worth trying! What you would have learned from Scheme 15 years ago is that combining nested scopes with indefinite extents is:

So Scheme did a very Pythonic thing here, requiring the programmer to identify intended scope explicitly (Scheme never guesses about this -- there are no inferences about intended scope, only explicit scope declarations).

Python didn't need that for its original scoping scheme, and it was no sin then to leave it out. The more Python tries to accomodate delayed code blocks (generator expressions are an instance of that, and it's not the "generator" part that's creating the problems), though, the more users will struggle with the lack of explicit scoping. The "delayed binding" guess usually works in the simplest examples (but so does the "early binding" guess), while nested "let" blocks are usually absent in the simplest Scheme functions. People never leave well enough alone, though, so I hope generator expressions don't become another "minor convenience" that's viewed as a "minor annoyance" a year later.



More information about the Python-Dev mailing list