[Python-3000] Efficient LC's which don't leak the iteration variables (was Re: Py3k release schedule worries)

Jim Jewett jimjjewett at gmail.com
Wed Dec 20 22:31:03 CET 2006


On 12/20/06, Guido van Rossum <guido at python.org> wrote:
> On 12/20/06, Jim Jewett <jimjjewett at gmail.com> wrote:

> >     [(lambda i=i: i) for i in range(10)]
> > =>
> >     [(lambda i=0_i: i) for 0_i in range(10)]

> > The argument to lambda can't be renamed, because it could be called as
> > a keyword.
>
> Perhaps you were thinking of a textual
> substitution? That's not at all how one would do this.

Yes; I think I was still thinking of the Py2->Py3 translator as well.

> I have no idea what you mean by "works as implemented". Do you propose
> *not* to fix the scope bleed of list comprehension loop control
> variables? That's not an option.

I propose that if fixing the scope bleed *in a straightforward manner*
entails other changes -- but those changes are restricted to
expressions inside the the list comprehension -- then those other
changes should be considered.

Changes to scope resolution aren't great, but there will be one here
anyhow (the "scope bleed" itself), and if something even more obscure
also changes -- that would be a reasonable price to pay for a simpler
solution.

-jJ


More information about the Python-3000 mailing list