Arrays of functions can be obtained using ⎕OR
(Object Representation) and the fact that such objects implicitly become reconstituted into functions when used as operands. (You can also do it explicitly using ⎕FX
.) It is easiest to define some helper operators first:
_Arrayify←{f←⍺⍺ ⋄ ⎕OR'f'}
_Apply←{2=⎕NC'⍺':⍺ ⍺⍺ ⍵ ⋄ ⍺⍺ ⍵}
Now, let's define some sample functions:
A←{2×⍵}
B←{⍵÷2}
C←{-⍵}
We create a 3-element vector of functions, and check that it is indeed a "normal" array:
fnArray←(A _Arrayify⍬)(B _Arrayify⍬)(C _Arrayify⍬)
⍴fnArray
3
Let's extract the second function and apply it:
(2⊃fnArray)_Apply 10
5
We can also create an application function, so we can use operators on it:
Apply←{⍺ _Apply ⍵}
fnArray Apply¨10
20 5 ¯10