[Python-Dev] Single- vs. Multi-pass iterability

Tim Peters tim.one@comcast.net
Fri, 19 Jul 2002 13:50:19 -0400


[Ping]
> ...
> I believe this is where the biggest debate lies: whether "for" should be
> non-destructive.  I realize we are currently on the other side of the
> fence, but i foresee enough potential pain that i would like you to
> consider the value of keeping "for" loops non-destructive.

I'm having a hard time getting excited about this.  If you had made this
argument before the iterator protocol was implemented, it may have been more
or less intriguing.  But it was implemented and released some time ago, and
I just haven't seen any evidence of such problems on c.l.py, the Help list,
or the Tutor list (all of which I still pay significant attention to).

"for" did and does work in accord with a simple protocol, and whether that's
"destructive" depends on how the specific objects involved implement their
pieces of the protocol, not on the protocol itself.  The same is true of all
of Python's hookable protocols.  What's so special about "for" that it
should pretend to deliver purely functional behavior in a highly
non-functional language?  State mutates.  That's its purpose <wink>.