Order of execution - adverbs & conjunctions

From J Wiki
Jump to navigation Jump to search


<=   =>

Adverbs and conjunctions have higher precedence than verbs. This means that an adverb or conjunction is executed before a verb. Furthermore, the left argument of an adverb or conjunction is the entire verb phrase that precedes it. The exact rules for parsing and execution are given in the Modifiers ancillary page of NuVoc

For practical purposes, the following examples illustrate the rules.

   a =. i.2 3
   +/"1 - a
_3 _12


Like all J sentences, the above sentence executes from right-to-left. Before the + can be parsed as being a dyad or a monad, the higher precedence " conjunction executes. The " conjunction takes the 1 as its right argument and the entire verb phrase to its left as its left argument. The verb phrase to the left is the adverb / which takes the + as its left argument. The following uses parentheses to make clear the order of execution that follows from the rules.

   ((+/)"1) (- a)


As mentioned earlier, simple examples with constants may require that you separate the constant that is the conjunction argument from the constant that is the argument of the derived verb.

   a (+"1) 1 2 3
   a +"1 (1 2 3)
   a +"1 [ 1 2 3


The last one uses the monad [ (same) that is defined to just return its argument. This is a bit shorter and avoids the use of parentheses.

<=   =>

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