[Python-Dev] Termination of two-arg iter()

Aahz aahz@pythoncraft.com
Mon, 15 Jul 2002 21:39:42 -0400


On Tue, Jul 16, 2002, Delaney, Timothy wrote:
> From: Aahz [mailto:aahz@pythoncraft.com]
>> 
>> I also think that's the wrong question, given the nature of
>> iterators; before you can ask that question, you need to demonstrate
>> that there is in fact a difference between an empty iterator and an
>> exhausted iterator.  I think that you can't demonstrate that, but I'm
>> certainly willing to be convinced.
>
> I think the definition that some people are using is:
> 
> An exhausted iterator is one for which StopIteration has already been
> raised.
> 
> An empty iterator OTOH is one which will raise StopIteration the next time
> next() is called. An iterator for an empty list is the simplest example of
> this, although it should be applied to any iterator.

In order to draw this distinction, you have to change the definition of
"iterator" that we've been using.  The sole protocol of iterator to date
has been the existence of a next() method that either returns an item or
raises StopIteration.  Making statements about what an iterator *will*
do counts as abuse IMO.  If you want a feature like that, go use
something else -- don't break the simplicity of iterators.
-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/

Project Vote Smart: http://www.vote-smart.org/