mjab@nanna.think.com (Michael J. A. Berry) (03/23/91)
The J status document for 2.9 lists various things with interesting names which aren't in the J dictionary (at least not the version I have). Have people out there had any luck figuring out the following: U .v gerund m :0 verb m :1 do-while -Michael Berry -- ============================================== Michael J. A. Berry Internet: mjab@think.com uucp: {harvard, uunet}!think!mjab telephone: (617) 234-2056 FAX: (617) 234-4444 ==============================================
cs450a03@uc780.umd.edu (03/23/91)
Well, since I've got J 3.0 with 2.9 docs, I suppose I can answer this
one... (Note, this has been tested on sun4 J 2.9)
nz =. ''::'x. }:^:(0=y.) y.'
3 nz 4
4
3 nz 2
2
3 nz 0
3
f =. 0: . , . nz . ({~) : 1
data=. 1 0 0 _1 0 0 1 0 0 2 0 0 3
data f 13 0
0 1 1 1 _1 _1 _1 1 1 1 2 2 2 3
data f (#data);i.0
1 1 1 _1 _1 _1 1 1 1 2 2 2 3
f =. 2&= . , . nz . ({~) : 1
data f (#data);i.0
1 1 1 _1 _1 _1 1 1 1
(I think, I didn't actually test this last variant, but it matches my
experience)
' given ':{ ger=. w . g . m . s
f =. ger : 1
' then: ':{ x f n;<b
' step 0':{ r=. c=. b }:i=. _1
' step n':{ r=. r g c=. c m x s i=. i+1
----------------------------------------------------------------------
also,
2 3 5 + . - . * . % :0 4
+-----+-------+-------+-------------+
|6 7 8|_2 _1 1|8 12 20|0.5 0.75 1.25|
+-----+-------+-------+-------------+
(This one's from memory)
In other words, you just box the results and stick them together.
Rank is supposed to be maxima of ranks of the argument functions (and
it doesn't have to be 4 functions for :0)
Raul Rockwell
P.S. (3.0 question) does anyone know what transitive n. (moments) is
supposed to do?
hui@yrloc.ipsa.reuter.COM (Roger Hui) (03/26/91)
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