next up previous contents index
Next: interlacing Up: Stream Previous: constant   Contents   Index


generator


Usage

for x in s repeat { ...}
for x in generator s repeat { ...}


Signature

generator: % $\to$ Generator T


Parameter Type Description
s % a stream


Description

This function allows the elements of a stream to be iterated.


Remarks

Since those generators are infinite, you should have a termination condition either inside the loop or in parallel with the generator in order to guarantee termination.


Example

The following code creates the stream of all the squares for $n \ge 0$ and prints those of them that are smaller than $1000$:
	import from MachineInteger, Stream MachineInteger;
	s := stream(0, (n:MachineInteger):MachineInteger +-> n^2);
	for x in s while x < 1000 repeat { stdout << x << newline; }



Manuel Bronstein 2004-06-28