Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Word for a non-iterator iterable?

Reply
Thread Tools

Word for a non-iterator iterable?

 
 
Leif K-Brooks
Guest
Posts: n/a
 
      02-06-2005
Is there a word for an iterable object which isn't also an iterator, and
therefor can be iterated over multiple times without being exhausted?
"Sequence" is close, but a non-iterator iterable could technically
provide an __iter__ method without implementing the sequence protocol,
so it's not quite right.
 
Reply With Quote
 
 
 
 
vincent wehren
Guest
Posts: n/a
 
      02-06-2005
Leif K-Brooks wrote:
> Is there a word for an iterable object which isn't also an iterator, and
> therefor can be iterated over multiple times without being exhausted?
> "Sequence" is close, but a non-iterator iterable could technically
> provide an __iter__ method without implementing the sequence protocol,
> so it's not quite right.


How about 'reiterable'?

--
Vincent Wehren
 
Reply With Quote
 
 
 
 
Alex Martelli
Guest
Posts: n/a
 
      02-06-2005
Leif K-Brooks <(E-Mail Removed)> wrote:

> Is there a word for an iterable object which isn't also an iterator, and
> therefor can be iterated over multiple times without being exhausted?
> "Sequence" is close, but a non-iterator iterable could technically
> provide an __iter__ method without implementing the sequence protocol,
> so it's not quite right.


Not just ``technically'' -- a dict is a good and very common example of
just such a "non-iterator, non-sequence iterable".

As you're focusing on "can be iterated over multiple-times", I like
"re-iterable"; it centers on what you can DO with the object, rather
than quibbling what it ISN'T


Alex
 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      02-07-2005

"vincent wehren" <(E-Mail Removed)> wrote in message
news:cu4kjo$d8s$(E-Mail Removed)1.nb.home.nl...
> Leif K-Brooks wrote:
>> Is there a word for an iterable object which isn't also an iterator, and
>> therefor can be iterated over multiple times without being exhausted?


The 'therefor' above is a non sequitor. A non-iterator iterable can also
be non-reiterable.

> How about 'reiterable'?


I agree. Reiterability is essential for some algorithms, while I am hard
put to think of a situation in which non-iterator-ness, by itself, is.

Terry J. Reedy




 
Reply With Quote
 
Oren Tirosh
Guest
Posts: n/a
 
      02-07-2005
Leif K-Brooks <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Is there a word for an iterable object which isn't also an iterator, and
> therefor can be iterated over multiple times without being exhausted?
> "Sequence" is close, but a non-iterator iterable could technically
> provide an __iter__ method without implementing the sequence protocol,
> so it's not quite right.


"reiterable". I think I was the first to use this word on
comp.lang.python.

If you have code that requires this property might want to use this
function:

..def reiter(x):
.. i = iter(x)
.. if i is x:
.. raise TypeError, "Object is not re-iterable"
.. return i

example:

..for outer in x:
.. for inner in reiter(y):
.. do_something_with(outer, inner)

This will raise an exception when an iterator is used for y instead of
silently failing after the first time through the outer loop and
making it look like an empty container.

When iter() returns a new iterator object it is a good hint but not a
100% guarantee that the object is reiterable. For example, python 2.2
returned a new xreadlines object for iterating over a file but it
messed up the underlying file object's state so it still wasn't
reiterable. But when iter() returns the same object - well, that's a
sign that the object is definitely not reiterable.

Oren
 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      02-07-2005

"Oren Tirosh" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> But when iter() returns the same object - well, that's a
> sign that the object is definitely not reiterable.


Unless, of course, __iter__ resets the iteration variable to its starting
value. But it would definitely not be simultaneously doubly iterable, as
one would want to compute a self crossproduct. And one could object that
such an __iter__ is not proper for an iterator (return self and do nothing
else). So such an __iter__ should better be written, perhap as a generator
function, to return an independent object with independently initialized
iteration variable.

Terry J. Reedy



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deployment of a WebApp that uses Word 10.0 via Interop.Word.dll object - How do I register the COM?? Luis Esteban Valencia ASP .Net 2 09-26-2008 08:26 PM
Open Word Doc in Word, not in Browser Franck ASP .Net 1 09-09-2005 07:37 AM
XML from Word -- formerly Create pdf from existing Word doc (asp.net) Sharon ASP .Net 0 07-27-2005 02:07 AM
How do I identify word<html><html>other word? Laura Perl 1 06-04-2004 11:32 PM
opening a word doc in word not browser Stephen Witter ASP .Net 0 05-18-2004 02:48 AM



Advertisments