23.3.3.25 Iterators In Guile

A simple iterator facility is provided to allow, for example,
iterating over the set of program symbols without having to first
construct a list of all of them. A useful contribution would be
to add support for SRFI 41 and SRFI 45.

— Scheme Procedure: make-iterator object progress next!

A <gdb:iterator> object is constructed with the make-iterator
procedure. It takes three arguments: the object to be iterated over,
an object to record the progress of the iteration, and a procedure to
return the next element in the iteration, or an implementation chosen value
to denote the end of iteration.

By convention, end of iteration is marked with (end-of-iteration),
and may be tested with the end-of-iteration? predicate.
The result of (end-of-iteration) is chosen so that it is not
otherwise used by the (gdb) module. If you are using
<gdb:iterator> in your own code it is your responsibility to
maintain this invariant.

Return the first argument that was passed to make-iterator.
This is the object being iterated over.

— Scheme Procedure: iterator-progress iterator

Return the object tracking iteration progress.

— Scheme Procedure: set-iterator-progress! iterator new-value

Set the object tracking iteration progress.

— Scheme Procedure: iterator-next! iterator

Invoke the procedure that was the third argument to make-iterator,
passing it one argument, the <gdb:iterator> object.
The result is either the next element in the iteration, or an end
marker as implemented by the next! procedure.
By convention the end marker is the result of (end-of-iteration).

— Scheme Procedure: end-of-iteration

Return the Scheme object that denotes end of iteration.

— Scheme Procedure: end-of-iteration? object

Return #t if object is the end of iteration marker.
Otherwise return #f.

These functions are provided by the (gdb iterator) module to
assist in using iterators.

— Scheme Procedure: make-list-iterator list

Return a <gdb:iterator> object that will iterate over list.

— Scheme Procedure: iterator->list iterator

Return the elements pointed to by iterator as a list.

— Scheme Procedure: iterator-map proc iterator

Return the list of objects obtained by applying proc to the object
pointed to by iterator and to each subsequent object.

— Scheme Procedure: iterator-for-each proc iterator

Apply proc to each element pointed to by iterator.
The result is unspecified.

— Scheme Procedure: iterator-filter pred iterator

Return the list of elements pointed to by iterator that satisfy
pred.

— Scheme Procedure: iterator-until pred iterator

Run iterator until the result of (pred element) is true
and return that as the result. Otherwise return #f.