Stefan Ram <firstname.lastname@example.org> wrote:
| email@example.com (Rob Warnock) writes:
| >iterators that I've found most useful, which one might call
| >"Resettable/Multi-Traversal" [though perhaps there is a more
| >traditional or standard name for it?], which provides:
| > - An initial setup function [in CLOS terms, an :AFTER method
| > on INITIALIZE-INSTANCE].
| > - An empty test [as with Alan Crowe's list].
| > - A get-next function [as with Alan Crowe's list, except...].
| > - A reset function that restores the state of the object *AND ALL
| > OF ITS ITERATOR CHILDREN* to the state which existed immediately
| > after the execution of the "initial setup" function.
| This is similar to Java's Iterator
| with its �hasNext()� and �next()� methods. The �next()�
| method will return a value and advance to the next value.
But this still lacks the "reset()" method, which is IMHO crucial
to implementing cross-products [and was what *most* of my "wirlex"
exposition was really about]!!
| However, I have found that when implementing more
| complicated iterators, like �get the next combination
| or permutation�, it is more easy for me to implement
| in terms of the following operations:
| - valid()
| Return wether a call to value() will deliever a valid value.
| - value()
| Return the current value, do not advance.
| - advance()
| Advance to the next value, if any.
Yes, I've also done it that way as well. As you observed,
"get_next()" can be expressed in terms of "value()/advance()",
and in fact the latter API gives the user a choice between
pre- & post-incrementing, which a single "get_next()" doesn't.
But again, like Java's, your API is still missing "reset()"!
Rob Warnock <firstname.lastname@example.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607