I'd like to collect various functions in a sequence and activate them by the sequence index, like in this simple example:
mul2: func [n] [2 * n]
mul3: func [n] [2 * n]
...
(pick [mul2 mul3] 1) 2 ; yields 2
It seems that mul2 is not treated like a function when it's referred to as a sequence item:
type? (pick [mul2] 1) == word!
Is it possible to arrange functions into sequences?
While experiencing with this example, I noticed that
function? mul2
complains that the argument of mul2 is missing, instead of returning true. Where am I wrong?
mul2andmul3are just wordsWhen you
getit's value, then you'll have the function:Notice that I used
:f(get-word) to get the unevaluated value (the function itself) instead off, becausefwill be evaluated and will require its parameters.And then you can use
f: