Rank conjunction "

From J Wiki
Jump to navigation Jump to search


<=   =>

The primitive " (double-quote, not two quotes) is the rank conjunction. Conjunctions haven't been introduced yet and there is more detail in a later section. For now, just think of a conjunction as similar to a dyad verb in that it takes a left and right argument and has a result. The particular use of " of interest here is when the left argument is a verb and the right argument is a noun. Yes, conjunctions can take verb arguments, as well as noun, whereas a verb can take only noun arguments.

In the section on names there was an example where you directly defined a name as a verb.

   plus =. +

This style of definition is more direct than the type you used to define centigrade. It is called tacit definition and is dealt with in more detail in a later section. The name plus is defined as the primitive + and thus has the same rank as + of 0 for monad and 0 0 for dyad.

The rank conjunction produces a new verb from its left argument with the rank information from its right argument.

   plus000 =. + " 0 0 0


The right argument for " is the rank information for the primitive + that is given in NuVoc (look up + and note the rank information with the names). The first 0 is the rank of the monad argument. The second and third 0's are respectively the rank of the dyad left and right arguments.

Since plus000 is + with same ranks as the primitive + it should behave just as does + or plus. You can verify this with a few experiments borrowed from the previous section on agreement.

   a =. i. 2 3
   a plus000 a
0 2  4
6 8 10
   a plus000 1 2 3
|length error
|   a   plus000 1 2 3


The length error occurs because the arguments do not agree as per the previous section. The left frame is 2 3 and the right frame 3, and 3 is not a prefix of 2 3; there are extra cells from the left argument without corresponding cells from the right argument.

However, it seems reasonable to want to add the list 1 2 3 to each list in the left argument. You know what you want it to do. Visually:

0 1 2   +   1 2 3      gives   1 3 5
3 4 5       ...                4 6 8



You want a variation of + that adds lists from its left argument to lists from its right. You can do that by changing the arguments to the " conjunction to indicate that the dyad left and right ranks are lists.

   plus011 =. + " 0 1 1
   a plus011 1 2 3
1 3 5
4 6 8
   1 2 3 plus011 a
1 3 5
4 6 8


In practice you wouldn't bother to give a name to such a specific application of + and you would instead use the expression directly.

   1 2 3 +" 0 1 1 a
1 3 5
4 6 8


Since + is applied dyadically and both ranks are 1, you can use the shorter form of +"1 which uses 1 for the rank of all arguments.

   1 2 3 +"1 a
1 3 5
4 6 8


In this case, the left frame is empty with a cell shape of 3 and the right frame is 2 with a cell shape of 3. Empty is a prefix of 2, and so the frames agree.

There is one thing you have to be aware of.

   a +"1 1 2 3
|length error
|   a    +"1 1 2 3


The problem is that J doesn't know that you want the first 1 to be the argument to " and the second 1 to be part of the constant 1 2 3. What happens is that the constant 1 1 2 3 is used as the right argument of " and since " is defined to allow only arguments of 1 2 or 3 numbers, there is a length error. You need to let J know that the 1 belongs to the " and that the 1 2 3 is a constant. You can make this clear by using parentheses.

   a (+"1) 1 2 3
1 3 5
4 6 8
   a +"1 (1 2 3)
1 3 5
4 6 8


<=   =>

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