Generate an array using code

genarray size code

Creates a new array with of the size and with items initialized with code. Size has to be a positive integer value. Code is a list of instructions, where the value of the last instruction is used to initialize item. Code is executed as a function: all local variables and functions will be destroyed on exit from the code block. A variable :index is available in the code block, with value corresponding to the index of currently initialized item of the array.

Example:

"a := genarray 5 [:index^2]
print :a

Output:

{1 4 9 16 25}

See also:

array - create an array from values
newarray - create an array of a given size

Array

Table of Content