In [ ]:
tab=: /~
In [ ]:
(];*.tab;!tab) _2+i.7
In [ ]:
2 3 5 + 10 20 30
The "adverb" in J takes a verb argument and returns another verb, typically related. The behaviour is much like in English: "run quickly", is the verb "run", modified by the adverb "quickly".
The J adverb / results in a verb that applies to each pair of elements, compare with above:
In [ ]:
2 3 5 +/ 10 20 30
In [ ]:
2 3 5 */ 10 20 30
In [ ]:
0 1 2 3 + 0 1 2 3
In [ ]:
+~ 0 1 2 3
In [ ]:
+/~ 0 1 2 3
In [ ]:
tab=. /~
In [ ]:
+ tab 0 1 2 3
In [ ]:
* tab 0 1 2 3
In [ ]:
i.7
In [ ]:
_2+ i.7
In [ ]:
] _2+i.7
In [ ]:
3 *. 4
In [ ]:
*.tab _2+i.7
In [ ]:
2!4
In [ ]:
!tab _2+i.7
The expression in parentheses:
```];*.tab;!tab```
is therefore seen to be of the form:
```f;g;h```
for verbs f g and h. It happens that ; is also a verb, so this expression is a list of 5 verbs!
To understand this, consider a simpler list of 3 verbs commonly seen in mathematics. Suppose f and g are functions, then:
```(f + g) x```
is typically defined to be
```f(x) + g(x)```
In J, this concept is extended to any type of function. Given verbs f g and h, then:
```(f g h) x```
is defined as
```(f x) g (h x)```
Example:
In [ ]:
(] + %) 1 2 3 4 NB. % is the reciprocal
In [ ]:
(] ; %) 1 2 3 4
J interprets a list of 5 verbs by creating a fork from the rightmost 3 verbs, then another fork from the new verb and the two remaining verbs.
It may be seen that:
```(];*.tab;!tab)```
is a verb that returns the identity; the LCM table; and the combinations table; all linked together.
Lets try it with a different argument:
In [ ]:
(];*.tab;!tab) 3+i.7
In [ ]:
!table 3+i.7 NB. right argument only
In [ ]:
0 1 2 3 !table 3+i.7 NB. left and right arguments
In [ ]: