[Python-Dev] PEP 289: Generator Expressions (second draft)

Guido van Rossum guido at python.org
Thu Oct 23 00:20:30 EDT 2003


> Guido:
> > > I probably missed it in this monster of a thread, but how do
> > > generator expressions do this?  It seems that they'd only make
> > > reduce more efficient, but it would still be just as needed as
> > > before.
> > 
> > All we need is more standard accumulator functions like sum().  There
> > are many useful accumulator functions that aren't easily expressed as
> > a binary operator but are easily done with an explicit iterator
> > argument, so I am hopeful that the need for reduce will disappear.
> 
> But this would still be true even if we introduced such functions
> *without* generator expressions, i.e.  given some new standard
> accumulator foo_accumulator which accumulates using foo_function, you
> can write
> 
>   r = foo_accumulator(some_seq)
> 
> instead of
> 
>   r = reduce(foo_function, some_seq)
> 
> regardless of whether some_seq is a regular list or a generator
> expression.
> 
> So it seems to me that generator expressions have *no* effect on the
> need or otherwise for reduce, and any suggestion to that effect should
> be removed from the PEP as misleading and confusing.

After some thinking, I agree.  The only (indirect) link is that
generator expressions make it more attractive to start writing
accumulator functions, and having more accumulator functions available
eliminates the need for reduce().

I'll update the PEP as needed (Raymond already toned down its mention
of reduce()).

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



More information about the Python-Dev mailing list