Newsgroups: comp.lang.apl Path: utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!geac!itcyyz!yrloc!hui From: hui@yrloc.ipsa.reuter.COM (Roger Hui) Subject: Re: Forks, Hooks and With in J Message-ID: <1991Jun11.000420.3398@yrloc.ipsa.reuter.COM> Reply-To: hui@yrloc.ipsa.reuter.COM (Roger Hui) Organization: Iverson Software Inc. References: Date: Tue, 11 Jun 91 00:04:20 GMT Comments on recent postings by Kjell Post, Raul Rockwell, and Bill Wicker. Expressions in J are better represented as trees than as DAGs. For example, try representing (a+b)*(b+c) as a DAG. & , like all other conjunctions, accepts noun or verb arguments, thereby giving rise to four possible cases of derivations. In principle, the four cases need not be related, nor do the monadic and dyadic defns. m & n undefined m & v with, m&v y is m v y ; x m&v y has empty domain u & n with, u&n y is y u n ; x u&n y has empty domain u & v compose, u&v y is u v y ; x u&v y is (v x) u (v y) Many useful verbs can be defined as m&v or u&n : 0&- negation ^&0.5 square root 0&< positive _1&* negation 10&^. base-10 log a.&i. ASCII code +&1 increment 0&{ first -.&' ' remove blanks -&1 decrement _1&{ last 2&(-~\) first difference All verbs are ambivalent, although some verbs have empty monadic or dyadic domains. Whether the monadic or the dyadic definition of a verb is applied, is determined by context, as defined by the first three parsing rules in Table 2 of the dictionary. These parsing rules apply to all verbs (whatever their derivation). In the fork (f g h), f and g are ambivalent, and whether f or h have empty monadic or dyadic domains would not be "discovered" until the derived verb is applied. For u=.f@[ g h@] , x u y u y x (f@[ g h@]) y (f@[ g h@]) y defn of u (x f@[ y) g (x h@] y) (f@[ y) g (h@] y) defn of fork (f x[y) g (h x]y) (f [ y) g (h ] y) defn of @ (f x) g (h y) (f y) g (h y) defn of [ and ] As in the above example, and as specified in the dictionary, a fork (hook) is an isolated sequence of 3 verbs (2 verbs). Parentheses may be required to effect that isolation. The explicit verb trim=.'(-.'' ''=y.)#y.' : '' can be stated tacitly as -.&' ' . ("Explicit" because the argument is explicitly mentioned; "tacit" because not.) Translations more faithful to the original: -.@(' '&=) # [ #~ -.@(' '&=) As noted in Bill Ricker's msg, #~ (-. ' '&=) is not an equivalent computation. (-. ' '&=) is a hook not because -. is dyadic (it is ambivalent), but because the parsing rules specify that an isolated sequence of 2 verbs is a hook. This derives a verb v, whence #~ v is an isolated sequence of 2 verbs, and is another hook. J 3.1 has an explicit-to-tacit translator: 'x.+y.' : 11 +-+-+-+ |[|+|]| +-+-+-+ '(x.+y.)*(x.-y.)' : 11 +-------+-+-------+ |+-+-+-+|*|+-+-+-+| ||[|+|]|| ||[|-|]|| |+-+-+-+| |+-+-+-+| +-------+-+-------+ '+/y.' : 11 +-----+-+-+ |+-+-+|@|]| ||+|/|| | | |+-+-+| | | +-----+-+-+ '(-.'' ''=y.)#y.' : 11 +--------------------+-+-+ |+--+-+-------------+|#|]| ||-.|@|+-------+-+-+|| | | || | ||+-+-+-+|@|]||| | | || | ||| |&|=|| | ||| | | || | ||+-+-+-+| | ||| | | || | |+-------+-+-+|| | | |+--+-+-------------+| | | +--------------------+-+-+ The last result is the verb -.@((' '&=)@]) # ] (a fork). Not all explicit verbs can be so translated. ----------------------------------------------------------------- Roger Hui Iverson Software Inc., 33 Major Street, Toronto, Ontario M5S 2K9 (416) 925 6096