This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Scheme style auto-resizing hashtable (fwd)


In response to my:
> What a strange statement!  What do you think map and for-each are?

hjstein@bfr.co.il (Harvey J. Stein) wrote:
> I believe the distinction was btw iterators (as in overloading + in
> C++) & mappers (as in map, for-each, ...).

I may have have read some of these messages too quickly (there is a
*lot* of traffic on the Guile mailing list), but the impression
I got was the issue was "interators" vs functions like hash->list.

However, I want to emphasize that the term "iterators" is much
more general than the C++ overloading of operator+.  In general,
it could refer to any technique/API for traversing the elements
of a collection.  Most commonly, it does refer to some kind of
"cursor" object which has an operation to get the current value,
and move to the next element.  Examples include the C++ STL
iterators, and the new Java (JDK 1.2) collections interfaces.
That type of iterator is perhaps not very Schemely, but note that
an input port is exactly such an iterator.

A mapper is more restricted kind of iterator.  It is more-or-less
equivalent to the kind of iterators first (?) seen in CLU, and
now in other languages (e.g. JavaScript):

    for (ID in COLLECTION) use(ID);

You can call that an iterator or a mapper, but in any case it is
a kind of iterator facility.  However, it is not as powerful as
a "cursor-style" iterator.  For example, it is harder to do a
merge-style operation.  A cursor-style iterator is inherently
state-dependent, which may be anathema to the pure functional
language adherents.  However, side effects are well within the Scheme
tradition, and the kind of hashtable we are talking about is
very stateful.

A simple Scheme-style iterator:

(hash-key-iterator HASHTABLE) -> ITERATOR

where ITERATOR is a zero-argument procedure whose first call
returns the first key, the second call returns the next key,
and so on.  When there are no more elements, an end of file
object is returned.

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner