[Python-Dev] Possible resolution of generator expressionvariablecapture dilemma

Jeremy Hylton jeremy at zope.com
Thu Mar 25 15:08:28 EST 2004


On Thu, 25 Mar 2004 02:34:10 -0500
 "Raymond Hettinger" <python at rcn.com> wrote:
> I do not view genexps as "convenient" short-forms for
> real generators.
> Instead, they represent memory/resource friendly versions
> of list comps
> which have been fabulously successful and have helped
> move us away from
> map/lambda forms.  I believe they will make the language
> more fluid,
> cohesive, and expressive.

It would be great to revise some existing code to use
generator expressions.  I find it hard to judge their
effect, but am inclined to agree with you.  I like list
comprehensions a lot.
 
> In deciding on semantics, we would all rather trade away
> some power in
> exchange for greater clarity about what the expression
> will do without
> having to run it.  Put another way, human
> interpretability is more
> important than supporting weird usages.  With that
> criteria,
> early-binding is looking to be least nuanced approach.

If readability counts, I think the standard binding rules
make the most sense.  The examples I've seen that depend on
differences in binding all seem like edge cases to me.  I
don't expect generator expressions in for loops will be a
common usage.  Put another way, in the cases where it
matters, I don't expect either option to be ovious or
intuitive.  If there's no obvious solution, I'd rather see
the consistent one.

Jeremy



More information about the Python-Dev mailing list