Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think.com!news!mjab From: mjab@godot.think.com (Michael J. A. Berry) Newsgroups: comp.lang.apl Subject: Re: Some General Questions about J Message-ID: Date: 25 Feb 91 16:54:38 GMT References: <1991Feb23.234505.5960@csi.uottawa.ca> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 137 In-Reply-To: cbbrowne@csi.uottawa.ca's message of Sat, 23 Feb 91 23:45:05 GMT Newsgroups: comp.lang.apl From: cbbrowne@csi.uottawa.ca (Christopher Browne (055908)) Keywords: n Nntp-Posting-Host: prgc Organization: CSI Dept., University of Ottawa Date: Sat, 23 Feb 91 23:45:05 GMT I'm in the process of trying to assimilate some sort of understanding of the J language. . . . c) Matrix Referencing (the "" operation) This shouldn't be TOO hard... I'm not too sure what you mean by the "" operation. In original APL, one could grab part of a matrix by doing something like the following: (I'll add a little J in to substitute for those operators that are not in ASCII...) EXPENDITURES=. 2 3 6 $ 161 161 161 164 164 164 9 3 11 6 4 4 10 17 22 9 11 20 130 132 184 197 163 0 1 7 9 10 5 6 21 24 8 11 17 161 EXPENDITURES 161 161 161 164 164 164 9 3 11 6 4 4 10 17 22 9 11 20 130 132 184 197 163 0 1 7 9 10 5 6 21 24 8 11 17 161 I'd then like to add things up with respect to the second index. I'd use the operation: +/[2]EXPENDITURES getting: 180 181 194 179 179 188 152 163 201 218 185 167 Actually, assuming an index origin of 0 as in J, that expression would be +/[1]EXPENDITURES In J, it's something annoying like +/ {Ugliesomitted{MoreUglies{EXPENDITURES Question 1) What should those two sets of uglies be? These are not the "uglies" you want. In both traditional APL and J what you are doing is not a selection of elements or "grabbing part of a matrix" (what { does) but rather, specifying how to carve up EXPENDITURES for +/. The confusion probably comes from the fact that square brackets were used for both selection and axis specification in APL. The two uses are unrelated. Question 2) There must be some general J idiom for doing this sort of thing. What might it be? In J, one would write +/"2 EXPENDITURES. This is read "sum rank two of EXPENDITURES" or "apply summation to the rank-2 cells of EXPENDITURES." The rank operator is not new with J. It was in Dictionary APL and Sharp APL (and maybe others as well). The [] notation was used for several different things in APL. In all cases, the syntax was anomalous since a pair of symbols was used where other APL functions and operators use a single symbol. Even the $24 documentation of J may not tell you all you want to know. If you want to read more about the rank operator, I suggest: Berneky, Robert "An Introduction to Function Rank" in the Proceedings of APL 88 (ACM). To understand more of the roots of J, I suggest: Iverson, Kenneth E. "A Dictionary of APL" APL Quote-Quad Vol. 18, Number 1, September 1987. The J distribution includes a file "references" with pointers to articles on J itself. Here is a sample J session illustrating the use of the rank operator to solve your problem: $ /public/j/sun4/j J Version 2.9 Copyright (c) 1990 1991, Iverson Software Inc. EXPENDITURES=. 2 3 6 $ 161 161 161 164 164 164 9 3 11 6 4 4 10 17 22 9 11 20 130 132 184 197 163 0 1 7 9 10 5 6 21 24 8 11 17 161 EXPENDITURES 161 161 161 164 164 164 9 3 11 6 4 4 10 17 22 9 11 20 130 132 184 197 163 0 1 7 9 10 5 6 21 24 8 11 17 161 +/"2 EXPENDITURES 180 181 194 179 179 188 152 163 201 218 185 167 Question 3) Why was this operation changed? I can see that the new way is far more explicit (and may be able to do things the old way couldn't). The square braces aren't used for anything in J now - they could have been used for the old operation. Why not? All the various things which [] used to do are done in J in different ways. The primary use of [] in APL was subscripting. Unlike {, however, it was impossible to write a rank-independent selection expression with the [] notation because you had to know how many semicolons to put in. (I'm sure there are good reasons for these things. I'd just like to know why...) -- Christopher Browne cbbrowne@csi.uofottawa.ca University of Ottawa Master of System Science Program -- ============================================== Michael J. A. Berry Internet: mjab@think.com uucp: {harvard, uunet}!think!mjab telephone: (617) 234-2056 FAX: (617) 234-4444 ==============================================