I did not refer properly to the place in the dictionary (perhaps I should learn Dan's way); the quoted paragraph is located in Dictionary/Dictionary/II. Grammar/F. Trains. I vaguely remember reading somewhere in the dictionary something similar to the following: x (vn c) <-> vn c x , x (c vn) <-> x c vn and x (a0 a1) <-> (x a0) a1 but my memory could be wrong.
________________________________ From: Jose Mario Quintana <[email protected]> To: Programming forum <[email protected]> Sent: Fri, December 4, 2009 6:03:44 PM Subject: Re: [Jprogramming] newbie question Dan explanation is very detailed. You can find a brief one in the Dictionary Appendix F Trains: " A two-element train of a conjunction with a noun or a verb produces an adverb. For example,&.> produces an adverb that might be called “each”, and the adverbbc=:<" might be called “box cells” because, for example,0 bc x would box the atoms ofx . " That bident and the next one in that appendix (adv adv) are essential for tacit adverbial programming (see the tacit filter definition). ________________________________ From: Dan Bron <[email protected]> To: Programming forum <[email protected]> Sent: Fri, December 4, 2009 5:42:51 PM Subject: Re: [Jprogramming] newbie question Richard Donovan wrote: > Can you/anyone please explain the name=: 'body' (1 :) syntax? J primitives execute only when provided all of their arguments. Nouns take 0 arguments, monads take 1, dyads take 2, adverbs take 1, conjunctions take 2*. So a conjunction will not execute until provided two arguments. If you only provide a conjunction 1 argument, it holds on (bonds) to that argument, and patiently waits for the missing input. How does it wait? By deriving an adverb, whose (single) input is the missing argument, of course! ** Such beasts are known as "bonded conjunctions". An example: compose =: 2 : 'u@:v' type 'compose' +-----------+ |conjunction| +-----------+ resultOfCompose =. + compose - NB. Give two arguments type 'resultOfCompose' NB. This conj outputs a verb when fully parm'd +----+ |verb| +----+ resultOfConj2 =. + compose NB. Now only give 1 argument type 'resultOfConj2' NB. it's an adverb +------+ |adverb| +------+ resultOfConj2 NB. Holding on to + and waiting... +conj - resultOfConj2 NB. Adverbs take 1 argument, on the left +@:- * resultOfConj2 NB. Reusable! +@:* Bonded conjunctions are higher-order analogs to bonded dyads (2-arg verbs), which derive a monad (1-arg verb), which wait for the missing argument, as in square=:^&2 and square 7 . Now, the primitive : is a conjunction. Used "normally", we give it both its arguments at once as in 3 : '^y' . But like any other conjunction, we may decide to give it one argument now, and the other one "later", like so: defineAVerb =: 3 : NB. Must wait for verb body '^ y' defineAVerb NB. Here's one 3 : '^ y' '*: y' defineAVerb NB. Here's a different one 3 : '*: y' or, perhaps more silly: bondedBody =: : 'x + y' NB. Must wait for part of speech 4 bondedBody NB. Dyad which sums its arguments 4 : 'x + y' 100 (4 bondedBody) 11 NB. And use it (anonymously) 111 2 bondedBody NB. Conj which makes a train of its (verb) arguments 2 : 'x + y' * (2 bondedBody) % NB. And use it (anonymously) * + % So Pepe's (1 :) was essentially defineAnAdverb though he didn't bother with the intermediate step of giving it a name, he just defined it anonymously and used it immediately (as with the parenthesized bondedBody expressions above). Since he used it immediately, the phrase 'body' (1 :) was essentially equivalent to 1 : 'body' bu the conjunction was executed very slightly (one stack operation) later. That's the "how". As for "why", I think Tracy hit it on the head: > I'm most struck by the novelty of seeing definition in the form >'programbody' (1 :) . > This small departure from the normal construction strikes me as easier to >scan The postfix notation allows one to focus immediately on the explicit definition, not on its decoration (you can pick that up afterwards). I agree that the number : prefix can be distracting, but personally I like to know the part of speech I'm defining for context (viz the difference between 4 : 'x + y' and 2 : 'x + y' above), so I prefer to lead in with verb def , dyad def , adverb def , etc. Of course, the part-of-speech of a particular explicit body is usually clear from its content (bondedBody is a contrived example). So this comes down to a personal preference. -Dan * Explicit adverbs and conjunctions may refer to their verbal argument's arguments, and even pend execution until those are provided, so it may take up to 4 arguments to execute a conjunction. ** So, put another way: 2-arg operators, given only 1 argument, simply derive 1-arg operators, waiting for the 2nd argument. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
