[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: iterators

This page is part of the web mail archives of SRFI 44 from before July 7th, 2015. The new archives for SRFI 44 contain all messages, not just those from before July 7th, 2015.

On Tue, Apr 29, 2003 at 01:46:03PM -0700, Per Bothner wrote:
> scgmille@xxxxxxxxxxxxxxxxxx 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.


Attachment: pgpfdrVPGPTBh.pgp
Description: PGP signature