[bitc-dev] Iterators

Jonathan S. Shapiro shap at eros-os.com
Thu Feb 26 18:56:54 EST 2009


So I was scratching my head about iterators, and I don't see why
something like the following would not work.

An iterator is a structure or capsule having methods value(), next(),
and hasNext().  value() returns the value at the current "position".
next() returns an iterator over the "rest" of the collection.
hasNext() tests for termination.

Given a construct like this, "forall" is simply a procedure that
applies a function to all values:

   forall: (fn (by-ref (Iterator 'a)) (fn 'a -> ()) -> ())

I'ld have to scratch my head a second about "fold", but I'm sure it's
comparably straightforward. The main issue here is to ensure that
appropriate inlining happens so that the higher-order nature of the
construct gets compiled out appropriately.

shap


More information about the bitc-dev mailing list