Make a sequence by performing a function on the index.
This function makes a sequence of type type whose i-th element is func(i) for 0 <= i < length. Type must be a subtype of <mutable-sequence>.
For example, I want a vector of the annual worth of an account of $10000 earning 10 percent annually. The below code creates that vector:
tabulate(10, method(x) 10000 * exp(x * .1) end, type: <vector>)
Or, to create a list of factorials, one could write this:
define function factorial(x :: limited(<integer>, min: 0))
=> (y :: <integer>)
if(x == 0)
1;
else
reduce1(\*, tabulate(x, curry(\+, 1)));
end if;
end function factorial;
tabulate(6, factorial);
| length | An instance of <integer>. |
| func | An instance of <function>. The signature of func is (<integer>) => (<object>). |
| type: | An instance of <type>, a subclass of <mutable-sequence>. The default is <list>. |
| list | An instance of <mutable-sequence>. |