Skip to content

J Compositions

Vector 11:2, page 124

language design

Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 124

In Vector Volume 11 Number 1, Gordon Sutcliffe posed several questions on compositions in J. First, how is the following behaviour derived?

x u&v&w y <--> (v w x) u (v w y)
x u&v@w y <--> u v (x w y)
x u@v&w y <--> u (w x) v (w y)
x u@v@w y <--> u (w x) v (w y)

The conjunctions @ and & are defined in the J Introduction and Dictionary, release 2:

u@v y <--> u v y          x u@v y <--> u x v y          p.172
u&v y <--> u v y          x u&v y <--> (v x) u (v y)    p. 176

A conjunction (or adverb) applies to any verb, whether primitive, derived, or "user-defined" (p. 74, p. 78, and in examples throughout).

The parsing rules specify how sentences are interpreted: a consequence of the parsing rules is that (quoting from p. 79) "the left argument of an adverb or conjunction is the entire verb phrase that precedes it". Thus, u@v&w is parsed (u@v) &w, and

x u@v&w y
x (u@v) &w y                  parsing rules
(v x)  (u@v)  (v y)             & dyad
u (v x) v (v y)                 @ dyad

The other three cases can be derived similarly. The analysis of such compositions is the same in other APL dialects.

Mr Sutcliffe then proceeded to comment on trains of verbs (hooks and forks). A fork is a sequence of three verbs; a hook is a sequence of two verbs. Parsing from right to left and preferring forks over hooks (a consequence of the trident rules preceding the bident rule, p. 80), a unique meaning is assigned to a sequence of verbs of any length.

For example:

x (p q r s t u v) y
x (p q (r s (t u v))) y                           parsing rules
(x p y) q x (r s (t u v)) y                       fork dyad
(x p y) q (x r y) s x (t u v) y                   fork dyad

  (x p y) q (x r y) s (x t y) u (x v y)           fork dyad

  x (q r s t u v) y
  x (q (r s (t u v))) y                           parsing rules
  x q (r s (t u v)) y                             hook dyad
  x q (r y) s (t u v) y                           fork monad
  x q (r y) s (t y) u (v y)                       fork monad

Roger Hui
Iverson Software Inc.
Toronto, Canada