[Jprogramming] How to make this conjunction tacit
Dan Bron
j at bron.us
Mon Oct 7 20:23:36 UTC 2013
Pascal asked:
> How to make this conjunction tacit
> coerce =: 2 : ']`u at .v'
coerce =: ^:
< coerce (0=L.) 2
+-+
|2|
+-+
< coerce (0=L.) <2
+-+
|2|
+-+
This particular coercion is also available as a ready-made utility in the standard library as "boxopen" and its cousin "boxxopen" (which is the same except it leaves empty arguments unboxed).
Note that it was trivial to write coerce tacitly because we have a primitive conjunction that fits the bill (obviating the need for a user-defined conjunction). In the general case, it is not possible to write tacit conjunctions. To understand why, read through section §II.F in the DoJ, and note that while there are rules for producing tacit verbs (e.g. "fork" for +/ # %) and adverbs (e.g. "adverb train" for /\) there are no rules which produce conjunctions.
That said, it may be possible to synthesize or simulate a tacit conjunction through a series of tacit adverbs, e.g.:
shanghai=.(`]) (`(;:'`@.')) (@.(0 2 1 3))
(0=L.) < yyy
<`]@.(0 = L.)
But these tend to be very convoluted, difficult to both write and understand, and will commonly involve some degree of quoted code anyway, so it is just as well (actually, better) to write them explicitly in the first place.
One more note: depending on your needs, you might prefer (0<L.) to (0=L.) . The former boxes only unboxed nouns; the latter boxes unboxed nouns as well as anything with a depth _greater_ than one (e.g. try <<2, <<<2, etc).
-Dan
PS: In the good old days, §II.F contained a long and rich table of interpretations for various trains (i.e. sequences of words/word-classes) which made it possible, among other things, to write conjunctions tacitly.
Again, these turned out to be convoluted and difficult, and consequently infrequently used in practice. In turn, it was decided that the cost of supporting the trains table (i.e. scanning all the possibilities for every single sentence of J executed) was worth less than they were worth, so the decision was made to remove it and simplify both the language and the interpreter.
That happened in J5, I believe. Anyway, for those interested in archaeology, or simply in what the language used to permit, check out the old trains table available at [1] and reproduced below. The rows having product="conj" were all the ways a J programmer could express conjunctions tacitly.
[1] Cache of J4 Dictionary §II.F:
http://www.cs.trinity.edu/About/The_Courses/cs2322/jdoc/dict/dictf.htm
Train Product Interpretation
-------- ------- ---------------------
N0 V1 N2 noun x V1 y
V0 V1 V2 verb (x V0 y) V1 (x V2 y)
V0 V1 C2 conj V0 V1 (x C2 y)
A0 V1 V2 adv (x A0) V1 V2
C0 V1 V2 conj (x C0 y) V1 V2
C0 V1 C2 conj (x C0 y) V1 (x C2 y)
A0 A1 V2 conj (x A0) (y A1) V2
A0 A1 A2 adv ((x A0) A1) A2
C0 A1 A2 conj ((x C0 y) A1) A2
N0 C1 N2 verb x (N0 C1 N2) y
N0 C1 V2 verb x (N0 C1 V2) y
N0 C1 A2 adv N0 C1 (x A2)
N0 C1 C2 conj N0 C1 (x C2 y)
V0 C1 N2 verb x (V0 C1 N2) y
V0 C1 V2 verb x (V0 C1 V2) y
V0 C1 A2 adv V0 C1 (x A2)
V0 C1 C2 conj V0 C1 (x C2 y)
A0 C1 N2 adv (x A0) C1 N2
A0 C1 V2 adv (x A0) C1 V2
A0 C1 A2 conj (x A0) C1 (y A2)
A0 C1 C2 conj (x A0) C1 (x C2 y)
C0 C1 N2 conj (x C0 y) C1 N2
C0 C1 V2 conj (x C0 y) C1 V2
C0 C1 A2 conj (x C0 y) C1 (y A2)
C0 C1 C2 conj (x C0 y) C1 (x C2 y)
N0 A1 verb x (N0 A1) y
N0 C1 adv N0 C1 x
V0 N1 noun V0 y
V0 V1 verb x (or y) V0 V1 y
V0 A1 verb x (V0 A1) y
V0 C1 adv V0 C1 x
A0 V1 adv (x A0) V1
A0 A1 adv (x A0) A1
A0 C1 adv (x A0) C1 x
C0 N1 adv x C0 N1
C0 V1 adv x C0 V1
C0 A1 conj (x C0 y) A1
More information about the Programming
mailing list