Iterator definitions

Sather - Language Specification
Prev | Chapter 4. Class Elements | Next

# 4.5. Iterator definitions

Example 4-7. Example:

    elts!(once i:INT, x:FLT):T is ... end;

    iter_definition ==>
            [ private ] iter_name [ ( iter_argument { , iter_argument } ) ] [ :  type_specifier ] [ pre expression ] [ post expression ] is  statement_list end

Iterators are similar to routines but encapsulate iteration abstractions. Their names end with an exclamation point '!' and they may only be called within loop statements (See loop statements). Iterator arguments that are not marked 'once' are called hot and cause re-evaluation of that argument at each iteration (see also See Modes). As with routines, SAME is permitted only for a return type or out arguments.

The description of routine arguments and pre and post constructs also applies to iterator definitions. Iters may contain yield (See return statements) and quit (See quit statements) statements but may not contain return statements (See return statements). The semantics of iterator calls is described in the section on loop statements (See loop statements). The pre clause must be true each time the iterator is called and the post clause must be true each time it yields. The post clause is not evaluated when an iterator quits.

The semantics of iterators and loops are discussed in more detail on See Loops and Iterators.

Prev | Home | Next
Routine definitions | Up | Code inclusion and include clauses