In the
J programming language, a
fork is the special name given to a
composite verb made by
concatenating three
verbs. The general
format for a
monadic fork follows (
f and
h are
monadic, while
g is
dyadic, and
v is some
noun):
(f g h) v is identical to (f v) g (h v)
For example:
The concept of a fork also generalizes to dyadic verbs in a train:
x (f g h) v is identical to (x f v) g (x h v)
Again, an example:
The most important thing to note about the concept of a fork is that it allows extended chaining of verbs in a meaningful way, because a fork can also be a component of a fork (or a hook, which, as noted above, is just a special case of a fork).
For example, to find the distance of each element from the mean (an important step in finding the variance and standard deviation) we just do it:
(- +/ % #) v is
(] - (+/ % #)) v is
(] - (+/ % #)) v is
v - ((+/ % #) v) is
v - ((+/v) % (#v)) is
the pairwise subtraction of elements in v with their mean.
More information on extended chaining of J verbs can be found at train.