[Python-3000] Efficient LC's which don't leak the iteration variables (was Re: Py3k release schedule worries)
Nick Coghlan
ncoghlan at gmail.com
Thu Dec 21 09:56:29 CET 2006
Greg Ewing wrote:
> Jim Jewett wrote:
>
>> Knowing which i's to rename strikes *me* as tricky,
>
> It shouldn't be too hard if you approach it the
> right way. One way would be to temporarily change
> the symbol table entry for the loop var when
> compiling the loop body and any nested functions
> so that it refers to a different slot in the
> locals.
The more I think about it, the more I think it will be simplest to tackle the
list comprehension as a 'pseudo-scope'. These would still effectively create
new scopes, but because they're executed immediately, they can get away with
borrowing the local namespace and execution frame of the current function
rather than running independently.
The compiler already has to keep track of which scope it is in order to handle
closure variables - the idea would be to add a mechanism to the scope stack
whereby each entry could either be a 'real' scope (actual separate local
namespace) or a 'virtual' scope (names in the scope are remapped to start with
an appropriate numeric prefix in the current local namespace).
Georg, if you want to tackle this, go ahead. Otherwise, I'll look into it over
the next couple of weeks.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list