[Python-Dev] Possible resolution of generator expression variable capture dilemma (original) (raw)
Guido van Rossum guido at python.org
Wed Mar 24 08:30:08 EST 2004
- Previous message: [Python-Dev] Possible resolution of generator expression variablecapture dilemma
- Next message: [Python-Dev] Possible resolution of generator expression variablecapture dilemma
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
However, I'm suggesting something different. I'm not proposing to make it local to the loop -- its name will still reside in the enclosing namespace, and its value will still be available after the loop finishes. In fact, if it's not referenced from any nested scope, there will be no change in semantics at all.
What will change is perhaps best explained by means of the implementation, which is very simple. If the loop variable is referenced from a nested scope, it will be held in a cell. Now, on each iteration, instead of replacing the contents of the cell as a normal assignment would, we create a new cell and re-bind the name to the new cell.
If I had known Scheme 15 years ago I might have considered this -- it is certainly an interesting approach. I'll have to ponder this a lot more before accepting it now; the potential consequences seem enormous. (It also pretty much forces this particular way of implementing nested scopes.)
I think it's definitely out of the question before 3.0; it's too subtle a change to too fundamental a construct.
--Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] Possible resolution of generator expression variablecapture dilemma
- Next message: [Python-Dev] Possible resolution of generator expression variablecapture dilemma
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]