[Python-Dev] accumulator display semantics
Ian Bicking
ianb at colorstudy.com
Thu Oct 16 12:17:35 EDT 2003
On Thursday, October 16, 2003, at 05:00 AM, Alex Martelli wrote:
> Why not move the for loop, if needed, out of the hard-coded
> infrastructure and just have accumulator display syntax such as:
> acc[x*x for x in it]
> be exactly equivalent to:
> a = acc.__accum__(lambda x: x*x, iter(it))
> return a.result()
> i.e., pass the callable corresponding to the expression, and the
> iterator corresponding to the sequence, to the user-coded
> accumulator.
Seems simpler if you could get an iterator for [x*x for x in it] that
returned (x*x, x), then call acc.__accum__(that_iter). I suppose for
some accumulators you could sometimes avoid calling the expression, but
that doesn't seem like a big feature.
It seems like it complicates the semantics that you have to turn the
list comprehension's expression into a function, where (I imagine) it
doesn't get turned into a real function otherwise, but is executed
without a new scope.
--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org
More information about the Python-Dev
mailing list