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)

interators Per Bothner 29 Apr 2003 05:15 UTC

The iterator model is unclear to me.
First, the name "iterator" may not be the best choice.
When I use an "iterator" to iterate through a sequence,
in most languages I change the location of the iterator,
but the identity of the iterator object does not change.
In the proposed API, iterators themselvs are immutable,
and you move to a new position by getting a new iterator.
This is reasonable for a (mostly-)functional language
like Scheme, but perhaps "position" would be a better name?

The specification for iterator-value says it is an error to call
this function when the iterator is at the start *or* at
the end position.  If I have a sequence with N elements,
it has N+1 positions before, after, or between elements.
If iterator-value is an error for the two end positions,
that means there are only N-1 values you can access.  That is
obviously a problem.

My conclusion is the model is that there are N+2 iterators for
a sequence of N elements.  I guess this could be made to work,
but it is different from what I'd expect.  (Input ports follow
the N+1 model.)  I think there needs to be some motivation for
this model, and a little exploration of the consequences.

Btw: For Java collections, the "value" of am
iterator depends on whether you last moved forwards or backwards.
I.e. the number of states is (I believe) 2*N.  Not that I would
advocation such a model!

	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/