Sequence Procedure

Each time a Sequence method is called it returns the next in a series of values. They provide a natural way to represent the idiom Begin-Iterate-Terminate.

Combining these operations into a single procedure ensures the operations are invoked in proper order. If instead the operations were implemented using independent methods their common state would need to be passed between each call. In a sequence that global state is now local and is managed for you by the compiler. Each sequence does the work of three methods using less code while reducing complexity.

Within a sequence procedure, each time you want it to return a value, use a Yield statement. A Yield essentually does a return and then the next time the sequence is invoked it resumes from there. It's probably easiest to see how this works with a trivial example:


The sequence output can then be processed with a Do-From statement.


An example Sequence is in the partial.g file in the Phonecode program. That sequence is read by a loop in the encode.phone.g file. The load.dictionary.g method also uses a sequence from the Gilda Foundation library that reads lines of text from a file.

Method Procedure

Primitive Type