Essays/Hook Conjunction?

From J Wiki
Jump to navigation Jump to search

Hook is a 2-train, an isolated sequence of two verbs, introduced in APL by K.E. Iverson and E.E. McDonnell, Phrasal Forms, APL89, APL Quote-Quad, Volume 19, Number 4, 1989-08. It is defined as follows:

  (g h) y   ↔   y g h y
x (g h) y   ↔   x g h y

For example, the monad (=<.) is a test for integers and (+%)/ computes a continued fraction -- (+%)/20$1 is an approximation of the golden ratio. Hook is based on the S combinator of combinatory logic .

With over 17 years of hindsight, I believe it would have been better to use a conjunction (denoted by h. , say) to denote a hook rather than using a 2-train. Everything that can be done with the 2-train (f g) can be done with the conjunction h. ,  but  h. does not require a special parsing rule.

The original motivation for assigning a meaning to a train of length 2 was so that a train of any length (greater than 1) would be interpreted: A train with odd length is a sequence of forks; a train with even length is either a hook (if of length 2) or a hook followed by a sequence of forks (if of length >2). Again with hindsight, the alternatives are:

0. Leave trains of even length uninterpreted -- just signal error.

1. Assign the "at" meaning to it:

     (g h) y   ↔  g   h y
   x (g h) y   ↔  g x h y

That is, the capped fork meaning. You'd probably still have the capped fork. Compare:

   [: f0 [: f1 f2 f3 f4
   (f0 (f1 (f2 f3 f4)))

See also



Contributed by Roger Hui.