Apply code to items in collection
apply collection code
Recalculates values of items in collection using code. Code is a list of instructions,
where the value of the last instruction is used as the new value of an item. Code is executed
as a function: all local variables and functions will be destroyed on exit from the code block.
Variables :index
and :vaue
are available in the code block, with values corresponding to the index and the current value of
an item in the collection.
Example:
"a := range 1 5
print :a
apply :a [
let "x :value
if :index > 1 ["x += :a,(:index - 1)]
:x
]
print :a
Output:
{1 2 3 4 5}
{1 3 6 10 15}
See also:
array - create an array from values
newarray - create an array of a given size
genarray - create an array using code
Array
Table of Content