[Python-ideas] Explicit variable capture list

Brett Cannon brett at python.org
Sun Jan 24 15:17:27 EST 2016


On Sat, Jan 23, 2016, 22:55 Guido van Rossum <guido at python.org> wrote:

> On Sat, Jan 23, 2016 at 10:27 PM, Stephen J. Turnbull
> <stephen at xemacs.org> wrote:
> > Guido,
> >
> > Thank you for taking the trouble to address my rather confused post.
>
> You're welcome. And thanks for taking it as constructive criticism.
>
> > Guido van Rossum writes:
> >
> >  > If I were to deconstruct the original statement, I would start by
> >  > replacing the list comprehension with a plain old for loop.
> >
> > I did that.  But that actually doesn't bother me because the loop
> > index's identifier doesn't go out of scope.  I now see why that's a
> > red herring, but maybe documentation can be improved.
> >
> > Anyway, I wrote that post before seeing your explanation that things
> > just aren't that difficult, they all follow from "variable reference
> > as dictionary lookup".  The clue I needed was the way to view a scope
> > as an object, and then realize that all free variable references are
> > the same, except for visibility of the relevant scope to the other
> > code at the call site.
> >
> > For me it's now a documentation issue (I know why the comprehension of
> > lambdas work as they do, and I also know how to get the "expected",
> > more useful result).  I'll go take a look at the language reference,
> > and tutorial, and see if I think they can be improved.
>
> I expect that the tutorial just needs some touch-up or an extra
> section on these issues. But the language reference... Well, it's a
> mess, it is often confusing and not all that exact. I should take a
> year off to rewrite it from scratch (what a book that would be!), but
> I don't have the kind of discipline to finish long writing projects.
> :-(
>

Would doing something like the Ruby community where we write a spec using a
BDD-style so it's more a set of tests than verbiage be easier?

-Brett



> --
> --Guido van Rossum (python.org/~guido)
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160124/e3bbeda1/attachment-0001.html>


More information about the Python-ideas mailing list