Next: , Previous: , Up: Imperative Language Interpreter   [Index]


5.4 Traversable Collections

Traversing collections with for statements requires the interpreter to have the descriptions of the possible traversal modes for the applicable data types.

See (aime)For Statements.

The struct x1f4_progress_type descriptions include the traversable collection data type code and the codes of the data types by which the collection is traversed, together with introduction of the method by which the collections can be traversed.

See Application Defined Types.

See struct x1f4_progress_type.

The data type codes alone identify a collection traversal mode, with a traversable data type allowing any number of modes. The latter will differ in the data types by which the collection is traversed, which are the data types of extracted data. For an instance, an associate table of intrinsic text keys (like the ‘record’ one) and integer data may be traversed by the ‘text’ and ‘integer’ types.

See (aime)The Record Library.

The collection traversals proper are done via hidden if-do-while constructs. The initial if sets up for traversal, while the subsequent do-while carries it out. Algorithmically, what the two do is:

    if (set for initial position in data collection) {
	do {
	} while (set for the next position);
    }

The method part in the traversal mode descriptions spells out how the two statements are to be created, in the form of templates for the if and while statements.