If u and v are functions, then f=: u : v defines f to be a function whose monadic case is u and whose dyadic case is v
For example, if v=: +, then 3 v 4 is 7 and v 4 is 4, i.e. since the monadic case of + is the conjugate, which produces an effect only on a complex argument such as 6j10.
We may, however, define a function add that performs addition on two arguments, and increments a single argument. Thus:
In [ ]:
add=: >: : +
In [ ]:
3 add 4
In [ ]:
add 4
In [ ]:
add 4 5 6 7 8
In [ ]:
v=: +
In [ ]:
3 v 4
In [ ]:
v 4
In [ ]:
mag=: |
In [ ]:
res=: |
In [ ]:
y=: 3 _4 5 _6
In [ ]:
mag y
In [ ]:
4 res y
In [ ]:
4 mag y
In [ ]:
res y
In [ ]:
mag=: | : [:
In [ ]:
res=: [: : |
The cap function may also be used in a train to cause a verb that follows it to be applied monadically.
For example, a vector may be scaled to unit length by dividing it by its length, the length being the square root (%:) of the sum (+/) of the squares (*:) of its elements. Thus:
In [ ]:
scale=: ] % [: %: [: +/ *:
In [ ]:
scale y
In [ ]:
%: +/ *: scale y
In [ ]: