Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!kepler1!rjfrey From: rjfrey@kepler.com (Robert J Frey) Newsgroups: comp.lang.apl Subject: Re: Rank 0 catenation. Keywords: rank, catenate , array , box Message-ID: <594@kepler1.kepler.com> Date: 25 Jun 91 16:24:19 GMT References: <1991Jun24.161151.12366@watmath.waterloo.edu> Reply-To: rjfrey@kepler1.UUCP (Robert J Frey) Organization: Kepler Financial Management, Ltd., Setauket, NY. Lines: 96 In article <1991Jun24.161151.12366@watmath.waterloo.edu> ljdickey@watmath.waterloo.edu (L.J.Dickey) writes: > >Suppose one is given the three arrays: > > a =. < " 0 m =. i. 2 3 > b =. < "(0) m + 12 > c =. < "(0) m + 24 > >How does one use these to create arrays d and e, whose displays are > > d >+----+----+----+ >|0 12|1 13|2 14| >+----+----+----+ >|3 15|4 16|5 17| >+----+----+----+ > e >+-------+-------+-------+ >|0 12 24|1 13 25|2 14 26| >+-------+-------+-------+ >|3 15 27|4 16 28|5 17 29| >+-------+-------+-------+ > >I found that these expressions do the job: > > d =. a ,"0 &. > b > e =. d (,,"0) &. > c > >My question is, do you know other ways of doing this? > > >-- Well, I wouldn't do that way ;-)! But given your original definition of a, b and c, you can also do: each =. '&.>':1 a=. <"0 i.2 3 b=. 12 +each a c=. 24 +each a then: e=. a ,each b ,each c Also, if list is a vector of boxed arrays of boxes: list=. (,each each/list note that '$each e' is: +-+-+-+ |3|3|3| +-+-+-+ |3|3|3| +-+-+-+ as expected. In the case of J I would defer the use of arrays of boxes until the 'last' step: a=. i.2 3 b=. a+12 c=. b+24 e=. <"1&.|:a,b,:c I think that a comparison of the two approaches suggests that the latter is probably a better way to do it. I was more familiar with APL2ish APL rather than Sharpish APL, so I tended to use a lot each's on boxed nouns when I first started using J. Because J treats a boxed noun as a reference to data, rather than as the data themselves, that often led to some pretty convolved sentences on my part. Does anyone know why people seem to feel that "data nesting" as in APL2 enclosed variables and "data referencing" as in J boxed nouns are incompatible with one another? They are probably implemented pretty much the same way as a data structure, the difference being the way the various verbs/functions of the language deals with them. A rank operator would be great to have in APL2 instead of all that function with axis stuff, and a foreach adverb and depth verb would be great to have in J (sometimes the way J pads out ragged results with zeroes/blanks/empty boxes makes me nervous). All that being said, I'm finding J extremely interesting. I'm quickly becoming one of the converted.