Node:Lazy vectors, Next:Re-structuring, Previous:Cyclic, Up:Sequences
A lazy vector uses the {} construct.
This takes an expression that gives the vector element
corresponding for each index (given by the ? construct).
Each element is only evaluated when it is needed, but once
it has been evaluated, its value is remembered for the future:
Q2> :a = [3 4 5]
Q3> :b = {a? + 100}
Q4> b # No elements are known yet.
...
Q5> b 2
105
Q6> b
_ _ 105 ...
Q7> b 1
104
Q8> b
_ 104 105 ...
Note that the operation ? form is the "inverse" of the operation {...}.
That is: {exp?} computes the same value as: exp,
if exp evaluates without side-effects to a sequence.
In fact, if the form ? follows an expression,
that expression is evaluated once only (eagerly),
not once per item (lazily). The compiler is essence treats
{... Exp? ...} as if it were:
:Temp=CoerceToSequence(Exp); {... Temp? ...}.
Identifiers declared directly (i.e. not further nested within
parentheses or function definitions) in a {...} form
are visible to all {...} in the same block.