Generators

These are functions that behave like tasks that return a series of results through a pipe.

Instead of returning one result, a generator produces a result and suspends itself until the caller is ready for another result. The result statement behaves like a return statement in that it delivers a result but when the generator is next called it continues from the point at which it left off.

e.g.

proc   fred
result   1

result   2

k  =  3

while   1   do

result   k

k  +=  2

done
endproc

x  =  generator   fred(a,b,c)

acc  =  0

for   j=0   while   j<10   step   j+=1   do

acc  +=  next   x

done

The 'generator' operator when applied to a function or method causes the parameters and context to be evaluated and prepares the generator for subsequent use. Beware that passing parameters by reference allows the values to be changed outside the generator.

Invoking a generator that has completed (exited via the return statement or fallen off the end of the function) will produce invalid values. Such values can be tested for with the is_valid function.

Generators can also be built from:

methods
x   =   generator   foo . bar(a,b,c)
x   =   generator   foo . CALC::sum(a,b,c)
x   =   generator   this . frame . CONSOLE::slider_watch()

indirect functions

func_name   =   "fred"
x   =   generator   (func_name)(a,b,c)

is equivalent to:
x   =   generator   fred(a,b,c)

indirect methods

func_name   =   "bar"
x   =   generator   foo . (func_name)(a,b,c)

is equivalent to:
x   =   generator   foo . bar(a,b,c)