A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-July/026768.html below:

[Python-Dev] The iterator story

[Python-Dev] The iterator storyOren Tirosh oren-py-d@hishome.net
Fri, 19 Jul 2002 09:23:51 -0400
> The Destructive-For Issue:
> 
>     In most languages i can think of, and in Python for the most
>     part, a statement such as "for x in y: print x" is a
>     non-destructive operation on y.  Repeating "for x in y: print x"
>     will produce exactly the same results once more.
> 
>     For pre-iterator versions of Python, this fails to be true only
>     if y's __getitem__ method mutates y.  The introduction of
>     iterators has caused this to now be untrue when y is any iterator.

The most significant example of an object that mutates on __getitem__ in
pre-iterator Python is the xreadlines object.  Its __getitem__ method 
increments an internal counter and raises an exception if accessed out of 
order.  This hack may be the 'original sin' - the first widely used 
destructive for.

I just wish the time machine could have picked up your posting when the
iteration protcols were designed. Good work.

Your questions will require some serious meditation on the relative 
importance of semantic purity and backward compatibility. 

	Oren




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4