Usage
stream t
stream f
stream h
stream(n, g)
stream(n, g, m, t)
stream(gen, t)
stream(gen, m, t)
Signatures
stream: T %
stream: (() T)
%
stream: ((MachineInteger, %) T)
%
stream: (MachineInteger, MachineInteger T)
%
stream: (MachineInteger, MachineInteger T, MachineInteger, T)
%
stream: (Generator T, T) %
stream: (Generator T, MachineInteger, T) %
Parameter | Type | Description |
---|---|---|
n, m | MachineInteger | machine integers |
t | T | an element |
f | () ![]() |
a function |
g | MachineInteger ![]() |
a function |
h | (MachineInteger, %) ![]() |
a function |
gen | Generator T | a generator |
Description
stream(t) returns the constant stream, while stream(f) returns the stream obtained by successive calls to
, stream(n, g) returns the stream
, stream(n, g, m, t) returns the eventually constant stream
and stream(h) returns the stream
where
for any
. When using generators, stream(gen, t) returns the stream
followed by
if
is finite, while stream(gen, m, t) returns the first
elements of the stream
followed by
.
See Also
orbit
Remarks
The functionmust be defined for all
(resp.
) and
must be defined for all
, even if you intend to use set! to set specific values of the stream later. Note that stream(f) does not necessarily returns a constant stream since each call to
can side-effect its environment. Constant or eventually constant streams do not repeatedly store their constant value and are therefore preferable. For example,
stores only one value no matter how many values are requested, while
stores
times
when its
element is requested.
Example
The following code creates the stream of the Fibonnaci numbers and prints the first 10 of them:
import from MachineInteger, AldorInteger, Stream AldorInteger; fib(n:MachineInteger, f:Stream AldorInteger):AldorInteger == { n = 0 or n = 1 => 1; f(n-1) + f(n-2); } sfib := stream fib; a := sfib.9; -- computes sfib.0 to sfib.9 stdout << a << newline;