Verb rank

From J Wiki
Jump to navigation Jump to search


<=   =>

A verb has a rank that determines how it applies to its arguments. A monad of rank k applies to the k-cells of its argument. A dyad of left rank kl and right rank kr applies to the kl-cells of its left argument and the kr-cells of its right argument. Verb rank is a powerful tool that controls the way a verb applies to arrays.

The ranks of a primitive verb are given in the NuVoc definition. For example, look up the definition of + . The rank information accompanies the name in the header. For + this is 0 Conjugate, which indicates the monad + (Conjugate) applies to the atoms. The dyad + (Plus) ranks are Plus 0 0 indicating it applies to atoms for each of the left and the right arguments.

Let's see how this works when adding two tables.

   a =. i. 2 3
   b =. 6 + a
   a
0 1 2
3 4 5
   b
6  7  8
9 10 11
   a + b
 6  8 10
12 14 16


The dyad + has left rank 0. This means it applies to the atoms of its left argument. Similarly the right rank is 0 and it applies to the atoms of its right argument. The verb takes an atom from its left argument, an atom from its right argument, and adds them together to create a partial result. It does this for each atom from the left and right argument and creates an appropriate number of partial results, which are then assembled into the result frame to create the final result.

In the example above the verb + has a left rank of 0. This means the left argument is treated as a 2 3 frame of atoms. Similarly, a right rank of 0 means that the right argument is treated as a 2 3 frame of atoms.

The frame of the result is determined by the frames of the arguments, and so its frame is also 2 3 and each cell is the result of adding an atom from the left argument with an atom from the right argument.

<=   =>

Primer Index               Hover to reveal titles   -   Click to access   -   Current page is highlighted
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
45 46 47 48
50 51 52 53 54 55 56 57
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
97 98 99 100 101 102 103 104 105 106