Path: utzoo!utgpu!news-server.csri.toronto.edu!torsqnt!geac!itcyyz!yrloc!hui From: hui@yrloc.ipsa.reuter.COM (Roger Hui) Newsgroups: comp.lang.apl Subject: Re: Do While in J? Message-ID: <1991Mar26.053718.4160@yrloc.ipsa.reuter.COM> Date: 26 Mar 91 05:37:18 GMT References: Reply-To: hui@yrloc.ipsa.reuter.COM (Roger Hui) Distribution: comp Organization: Iverson Software Inc. Lines: 27 A gerund is a verbal form that can be used as a noun, as "programming" in "programming is an art". Gerunds in J are arrays of atomic representations of verbs, and can be manipulated like other nouns. When recognized by adverbs and conjunctions, gerunds give rise to many useful verbs, such as do-while, if-then-else, case, and recursion. (See Bernecky and Hui paper in APL91.) The notation for gerunds has evolved since J 2.9. In particular, u`v (previously u .v) yields the atomic representations of u and v. If g=.v0`v1`v2 ... , then g/x inserts v0, v1, v2 between the items of x, repeating v0, v1, ... cyclically. It is therefore a generalization of the ordinary insert f/x (which inserts the single verb f). For example, +`*/}.,x,"0 y evaluates polynomial y at x using Horner's rule. If g=.p`b`c`r and f=.g\ , then f y is b y if p y is 0, and f y is y c f r y otherwise. Thus factorial can be define as fac=.*`1:`*`<: . From their use in g\, the verbs p, b, c, and r may be remembered as follows: proposition (* signum in factorial example) basis (1: constant function 1) combine (* multiply) reduce (<: decrement) Other verbs can be derived similarly, usually as g`:k for the conjunction `: (previously spelt : ), but also as g adv for certain cases (as with \). Roger Hui, Iverson Software Inc., 33 Major Street, Toronto, Ontario M5S 2K9 (416) 925 6096