[Python-Dev] accumulator display syntax

Guido van Rossum guido at python.org
Thu Oct 23 01:48:17 EDT 2003


(This is drawing to a conclusion.  Summary: Tim has convinced me.)

> > There are other places in Python where some rule is applied to "all
> > free variables of a given piece of code" (the distinction between
> > locals and non-locals in functions is made this way).  But there are
> > no other places where implicit local *copies* of all those free
> > variables are taken.
> 
> I didn't suggest to copy anything, just to capture the bindings in use at
> the time a generator expression is evaluated.

Sorry, I meant a pointer copy, not an object copy.  That's a binding
capture.

> This is easy to explain, and trivial to explain for people familiar
> with the default-argument trick.

Phillip Eby already recommended not bothering with that; the
default-argument rule is actually confusing for newbies (they think
the defaults are evaluated at call time) so it's best not to bring
this into the picture.

> Whenever I've written a list-of-generators, or in the recent example
> a generator pipeline, I have found it semantically necessary,
> without exception so far, to capture the bindings of the variables
> whose bindings wouldn't otherwise be invariant across the life of
> the generator.  It it turns out that this is always, or nearly
> almost always, the case, across future examples too, then it would
> just be goofy not to implement generator expressions that way
> ("well, yes, the implementation does do a wrong thing in every
> example we had, but what you're not seeing is that the explanation
> would have been a line longer had the implementation done a useful
> thing instead" <wink>).
> 
> > I'd need to find a unifying principle to warrant doing that beyond
> > utility.
> 
> No you don't -- you just think you do <wink>.

OK, I got it now.  I hope we can find another real-life example; but
there were some other early toy examples that also looked quite
convincing.

I'll take a pass at updating the PEP.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list