Most primitive functions in APL are already widespread. So, if you don’t come up with, your custom functions will already be distributed. For instance,
f←{÷1+*-⍵} ⍝ sigmoid, f(x)=1/(1+exp(-x))
will work with both arrays and scalars.
If you are making a fantasy and you have a non-pervasive function f
, you can turn it into an all-pervasive
g←{0=⍴⍴⍵:f⍵ ⋄ ∇¨⍵} ⍝ the pervasive version of f
which can be read as: if the argument is a scalar, apply f
to it, otherwise go recursively to each element of the argument.
source share