interators Per Bothner (29 Apr 2003 05:14 UTC)
Re: iterators [was: interators] Per Bothner (29 Apr 2003 05:29 UTC)
Re: interators scgmille@xxxxxx (29 Apr 2003 20:00 UTC)
Re: iterators Per Bothner (29 Apr 2003 20:45 UTC)
Re: iterators scgmille@xxxxxx (29 Apr 2003 21:36 UTC)

Re: iterators scgmille@xxxxxx 29 Apr 2003 21:36 UTC
On Tue, Apr 29, 2003 at 01:46:03PM -0700, Per Bothner wrote:
> xxxxxx@freenetproject.org wrote:
> >Well, they are still iterators, the difference is that instead of an
> >iterator object which is mutated as in other languages, we behave
> >functionally, returning a new state object from iterator-next.
>
> My question is: is the word "iterator" common for this kind
> of non-mutable iterator?  If not, perhaps another name, like
> "position" might be better.  "cursor" is another possibility.

Perhaps.  "cursor" makes much more sense than "position" though.

>
> One problem with the proposed model is that it requires *three*
> function calls for each iteration - and they all have relatively
> long names.  This cries out for a macro to make iteration less
> verbose.  (There are also performance implications of using three
> calls per iteration.)

In order for it to remain functional (which I think is an important
goal) you must have three calls.  With two, you must overload
iterator-next to return say #f if there is no next, which forces the
code to look like:

(let ((ni (iterator-next)))
  (if ni
      (begin (do-something (iterator-value ni))
             (loop ni))))

The allocation there is almost certainly a worse performance problem
than what is probably a very lightweight call to a predicate.

	Scott