[Python-Dev] xrange identity crisis

Greg Ewing greg@cosc.canterbury.ac.nz
Wed, 05 Jun 2002 17:08:32 +1200 (NZST)


> Maybe, the right way to go is to assure that iter(x) returns a freshly
> loaded iterator instead of the same iterator in the same state.

That would be a change to the semantics of all iterators,
not worth it just to fix a small oddity with xrange.
I think it's fairly clear that xrange is to be thought
of as a lazy list, *not* an iterator. The best way to
fix it (if it needs fixing) is to have iter(xrange(...)) 
always return a new object, I think.

It wouldn't be possible for all iterators to behave
the way you suggest, anyway, because some kinds of
iterator don't have an underlying sequence that can
be restarted (e.g. file iterators).

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+