[Python-Dev] accumulator display semantics

Phillip J. Eby pje at telecommunity.com
Thu Oct 16 14:26:13 EDT 2003

At 01:45 PM 10/16/03 -0400, Aahz wrote:
>On Thu, Oct 16, 2003, Raymond Hettinger wrote:
> > [Aahz]
> >>
> >> I'm having a difficult time following this discussion.  Would someone
> >> please write a PEP once things settle down?
> >
> > Peter's link is essentially a PEP already and covers all the essentials:
> >
> >    http://www.norvig.com/pyacc.html
>Gotcha.  Didn't realize he'd been summarizing the discussion.  Well,
>I'll hold my opinion on the whole proposal pending a PEP, but I'll make
>two comments on the proposal as it stands:
>* I'm strongly opposed to the return idea instead of raising
>StopAccumulation (which should be a subclass of StopIteration).  Using
>return this way is IMO unPythonic.
>* If we're using bracket notation, I think accumulators must return a
>list.  I think it would be a Bad Idea to permit other types (although I'm
>willing for leeway to permit list subclasses).

And while we're writing comments for the "Objections" part of the PEP...  :)

* This does nothing functions can't do today (with less magic and greater 
readability) over any iterable

* If you don't want to allocate memory for the whole list, you can always 
write an iterator object or generator function -- today, even in Python 2.2.

* If you really want a way to create a generator inline, let's just have a 
way to create a generator inline in 2.4.  And any accumulator functions you 
previously wrote for 2.2 or 2.3 will "just work" with the new kind of 
generator.  Note too, that inline generators would have other uses besides 
accumulation expressions.

More information about the Python-Dev mailing list