News flash: I'm going to Australia in February, so this Web site may be switched off at any time.
The Icon expression ``1 to 5
'' is a simple example of
a generator expression, that is, one that produces more than
one result.
You can write procedures that act as generators. In this example, Two_Powers is a procedure that takes two arguments a and b and generates the sequence of powers of two, from 2 to the a power to 2 to the b power:
procedure Two_Powers ( a, b ) #--Generates 2^a, 2^(a+1), ..., 2^b local i every i := a to b do # Let i = a, a+1, a+2, ..., b suspend 2^i; # Each time, return 2^i fail; # No more results; fail endThe statement ``
suspend e1
'' means
``return e1 as the next value of this procedure.''
The fail
statement means ``there are no more
values to return.''
john@nmt.edu