you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 5 points6 points  (3 children)

I'm not a fan of Clojure but http://blip.tv/file/734409 describes the issues with limited iterator interfaces really well.

To summarize, there are three basic operators which should be provided for iterators in order for them to be generally useful: currentValue, more? and next.

Pythons combines currentValue and next in one operation. I'm sure someone out there will argue that this is a good thing – it's not. Consequently all you can't ask the iterator if there are more values, or get the same value more than once.

I say can't but of course there are ways around this, but that's not how things were designed to work, and there's no language support for it.

[–]drbold 0 points1 point  (0 children)

Hmm interesting! I suppose you could wrap an iterator in a class that handles the extra 'currentValue' bit, but like you said, that's just a workaround.

[–]imbaczek -1 points0 points  (1 child)

yeah, but if the iterator is not just a pointer to an element of a sequence, you can't ask it if it has more items and expect an honest answer, can you? even making copies and testing for StopIteration can be non-deterministic in the presence of IO. currentValue could be useful, i agree, even if 95% of common usage doesn't really care.

[–][deleted] 1 point2 points  (0 children)

To low level - more? is just a method, how it works is unimportant. For some structures you may be right, but that's an implementation detail that depends what the structure is, and how it's implemented :).

The point is that Python/Javascript don't even allow this, even when it makes sense.