Subject: Re: Java discovers map
From: rpw3@rpw3.org (Rob Warnock)
Date: Sun, 05 Aug 2007 19:46:58 -0500
Newsgroups: comp.lang.lisp
Message-ID: <WomdnU560-sf8ivbnZ2dnUVZ_ruqnZ2d@speakeasy.net>
Stefan Ram <ram@zedat.fu-berlin.de> wrote:
+---------------
| rpw3@rpw3.org (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
| 
| http://download.java.net/jdk7/docs/api/java/util/Iterator.html
| 
|   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

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607