forward-iteration-protocol

Returns eight values used to implement iteration over the collection argument.

Only the collection argument this function was called with may be used as the collection argument to functions returned by this function.  Only the initial-state object and state objects returned by the next-state and copy-state functions may be used as the state argument to functions returned by this function.  Only the limit object may be used as the limit argument to the finished-state? function.

An example of the use of the iteration protocol is the following definition of a single-argument version of the do function:

define method do1 (f :: <function>, c :: <collection>)
let (init, limit, next, end?, key, elt) =
forward-iteration-protocol(c);
for (state = init then next(c, state),
until: end?(c, state, limit))
f(elt(c, state));
end for;
end method do1;

Exported from

Modifiers

open

Arguments

collectionAn instance of <collection>.

Values

initial-stateAn instance of <object>.  The initial iteration state object.
limitAn instance of <object> that is used by the finished-state? function to determine whether the iteration has been completed.
next-stateAn instance of <function>.  Its signature is next-state(collection, state) ⇒ new-state.
 This function steps the iteration by producing a new state from the associated collection and state.  The next-state function may or may not modify the state argument; it is an error to use a state value after it has been passed to the associated next-state function.  The copy-state function provides a mechanism for saving a particular state in an iteration for later resumption.
finished-state?An instance of <function>.  Its signature is finished-state?(collection, state, limit) ⇒ boolean.
 This function returns #t if the iteration of the collection has been completed, i.e., there are no other elements of the collection to consider.  It returns #f otherwise.  It is an error to use a finished state in a call to the associated next-state, current-element, current-key or current-element-setter functions.
current-keyAn instance of <function>.  Its signature is current-key(collection, state) ⇒ key.
 This function returns the unique key associated with state in the collection.  If the current-key function were called once with each state value produced during an iteration over a collection, the resulting sequence of values would contain every key from the collection exactly once; it would be the key-sequence of the collection.
current-elementAn instance of <function>.  Its signature is current-element(collection, state) ⇒ element.
 This function returns the element of collection currently indicated by state.
current-element-setterAn instance of <function>.  Its signature is current-element-setter(value, collection, state) ⇒ value.
 This function sets the element of collection indicated by state to value and returns value.  If collection is not an instance of <mutable-collection>, or if the value is not of a type acceptable to the collection, an error is signaled.
copy-stateAn instance of <function>.  Its signature is copy-state(collection, state) ⇒ new-state.
 This function returns a state that represents the same point in the iteration over collection as is represented by state.
Iterates over one or more collections for side effect.
The common-dylan module.
Whenever possible, we have tried to keep the Dylan module pristine and unextended, preferring to add our extensions to separate modules or libraries.
The class of collections, aggregate data structures.
The class of all Dylan objects.
The class of objects that can be applied to arguments.
Returns a sequence containing the keys of its collection argument.
The class of collections that may be modified.