Chapter 3 HOW TO UTILIZE J stdin, stdout J, Version 2.9 spelling error in J tutorial another mystery re J Dyalog APL questions (basic data representation) J comment styles *======================================== # stdin, stdout +------------------ | Leroy J. Dickey | <1991Apr5.143326.6264@watserv1.waterloo.edu> In article weg@convx1.ccit.arizona.edu (Eythan Weg) writes: >Hi there: >2) Is there a way to use J in a filter like cat file|J|awk|J...? I tried this little example. I created a file with these four lines in it: data =. i. 3 4 5 +/ data +/ "1 data +/ "2 data and then issued the command: cat t | J | more -5 . All worked as expected. In fact, the lines below were added to this file by the command ! J < t 60 63 66 69 72 75 78 81 84 87 90 93 96 99 102 105 108 111 114 117 10 35 60 85 110 135 160 185 210 235 260 285 30 34 38 42 46 110 114 118 122 126 190 194 198 202 206 *======================================== # J, Version 2.9 +------------------ | Peter S. Shenkin | <1991Feb24.200545.21350@cunixf.cc.columbia.edu> In article <1991Feb22.172035.18059@watmath.waterloo.edu> ljdickey@watmath. waterloo.edu (L.J.Dickey) writes: > >Several implementations of J, Version 2.9, are now available >on the file server > > watserv1.waterloo.edu > also known as 129.97.129.140 .. > sgi Oh boy! I just got J and put it up on my personal Iris (4d25tg, IRIX 3.2.1). I do intend to send in my $24, become a registered user and get the printed manual, but in the meantime, could some kind soul please tell me how to use these tutorial.js and tut/tut??.js files? Are they special J files that are to be invoked somehow from within J? If so, how? If not, how are they used? I tried "j < tutorial.js", and this prints the line "J Tutorial", then immediately exits. Other attempts, from within J, failed in more obvious ways. Suggestion to the Powers That Be: You might add a line to readme.doc, telling how to get started with the tutorial; I suppose a man page is too much to ask for :-) . +------------------ | Dean Kelly | <1991Feb24.212139.124@gacvx2.gac.edu> In article <1991Feb24.200545.21350@cunixf.cc.columbia.edu>, shenkin@cunixf.cc. columbia.edu (Peter S. Shenkin) writes: > In article <1991Feb22.172035.18059@watmath.waterloo.edu> ljdickey@watmath. waterloo.edu (L.J.Dickey) writes: ... deleted stuff > Oh boy! I just got J and put it up on my personal Iris (4d25tg, IRIX 3.2.1). > I do intend to send in my $24, become a registered user and get the printed > manual, but in the meantime, could some kind soul please tell me how to > use these tutorial.js and tut/tut??.js files? Are they special J files > that are to be invoked somehow from within J? If so, how? If not, how > are they used? > > I tried "j < tutorial.js", and this prints the line "J Tutorial", then > immediately exits. Other attempts, from within J, failed in more obvious > ways. The .js files are (apparently) the J equivalent of apl workspaces. Look in the rununix.doc file, if you picked it up in your .tar. It tells how to initiate the tutorial from within J. I haven't yet figured out just _what_ it does, however.....any suggestions??? ..more deleted stuff! +------------------ | L.J.Dickey | <1991Feb25.040757.4277@watmath.waterloo.edu> In article <1991Feb24.200545.21350@cunixf.cc.columbia.edu> shenkin@cunixf.cc. columbia.edu (Peter S. Shenkin) writes: >... >Suggestion to the Powers That Be: You might add a line to readme.doc, telling >how to get started with the tutorial; I suppose a man page is too much to >ask for :-) . It is my fault that the file "rununix.doc" was not included. I have corrected that. What you can do is this: (1) Start J (2) Within J, type either of the commands: )script 'tutorial.js" )sscript 'tutorial.js" [[NB. sws. The ) commands have been replaced with !:, the above can now be done as: script=. 0!:2 &< sscript=. 0!:3 &< script 'tutorial.js' NB. for example sscript 'tutorial.js' ]] (3) Then type tutorial '' However, I found that for my own purposes, that it was convenient to have a printed page near my screen, so that I could use the printed page as a model for what I typed. +------------------ | Robert Bernecky | <1991Feb27.053635.6228@yrloc.ipsa.reuter.COM> To get the J tutorial to run, try this: )script 'tutorial.js' tutorial '' [[NB. sws. see a previous article for the current solution ]] I think that'll do it. It works on my glorious msdos dinosaur. Bob *======================================== # spelling error in J tutorial +------------------ | David Wine | 11 Mar 91 22:45:21 GMT When I try the example from tutorial page Ib, I get a spelling error: '01234567' {~ ]: arcs 3725571555261237747274 5602627607332170423003 b=. '(i.,~x.)e.' cmFarcs=. '' ::(b,'y.+/..*x.,1') spelling error [[NB. sws. I'm not sure this helps, but the current tutorial gives q=. i.@(,~@[)e.] +/ . * ,&1@[ cmFROMarcs=. [ q |:@] NB. is the current tutorial online anywhere? ]] +------------------ | L.J.Dickey | <1991Mar12.041232.24797@watmath.waterloo.edu> In article wine@maui.cs.ucla.edu (David Wine) writes: >When I try the example from tutorial page Ib, >I get a spelling error: > > '01234567' {~ ]: arcs >3725571555261237747274 >5602627607332170423003 > b=. '(i.,~x.)e.' > cmFarcs=. '' ::(b,'y.+/..*x.,1') >spelling error I think that the problem might be the "/.." . Replace "y.+/..*x." by "y.+/ ..*x." I think that the parser tries to create "/. ." instead of "/ ..". I discovered this when trying to multiply two matrices together. a+/..*b would not work, but a+/ ..*b did work. [[NB. sws. .. has been replaced by . so that we use a+/ .*b NB. but the space is still important. ]] +------------------ | Harald Brandt | <1991Mar12.135159.28486@eua.ericsson.se> In article wine@maui.cs.ucla.edu (David Wine) writes: > When I try the example from tutorial page Ib, > I get a spelling error: > ... ... ... ... > cmFarcs=. '' ::(b,'y.+/..*x.,1') > spelling error /.. must be / .. i.e there must be a blank between the slash and the dot, otherwise it will be interpreted as an inflection of slash (or a double inflection as there are two dots, which is undefined). +------------------ | Roger Hui | <1991Mar19.060453.28135@yrloc.ipsa.reuter.COM> There have been some spelling changes in J Version 3. In particular, old spelling new spelling {: ] }: [ .. . . ` : `: :: : These changes should have been included in the status.doc file. I had updated the spelling in the tutorials that we (ISI) ship. It is possible that not all bulletin-board and ftp sites have had their tutorials updated with the new spellings. I will look into this. *======================================== # another mystery re J +------------------ | Eythan Weg | Hello there, J-speakers! I have found these problems for which I seek responses: 1) In J/PC version 3.3 I cannot fully load a workspace whose size is 45000 bytes. It ends with workspace full. I may or may not be able to copy individual objects depending on their size. why? Is it better in newer versions? 2) I have the following interaction on with jvax 3.2, which ends improperly, while identical interaction with J/PC 3.3 is glitchless. After that, the program stays hanging. What is it? beta +--------------+-+--------------+ |+-+-+--------+|%|+--------+-+-+| ||*|&|+-+-+--+|| ||+-+-+--+|@|+|| || | ||!|&|<:||| |||!|&|<:|| | || || | |+-+-+--+|| ||+-+-+--+| | || |+-+-+--------+| |+--------+-+-+| +--------------+-+--------------+ Ibeta ++-+--------------------------------------------------------------------------+ ||:|n=.80 [ l=.0 | || |$.=.>(y.<:0.5){(one;two) | || |one) x.=.|.x. [ y.=.-.y. [l=.1 | || |two)x=.>:+/ (((>:0{x.) beta >:i.n)% ( (+/x.) beta >:i.n ))*(y.^>:i.n) | || |x=.(*/((|,-.)y.)^x.)*x | || |y=.(0{x.)* (0{x.) beta 1{x. | || |x=.x%y | || |(l*-.x)+x*-.l | ++-+--------------------------------------------------------------------------+ Sned ++-+------------------------------------------+ ||:|(-: x.) Ibeta (y.*0{x.)%(y.,1) +/ . * (x.)| ++-+------------------------------------------+ 2 6 Sned 3.5 domain error 3) Another unrelated problem is the interface to J on unix. Does anyone has an improved version of Michael Berry's J-interaction mode for Gnu emacs? I find myself withis dilemma: J on pc seems to behave fairly well except that the workspace limitations are not always acceptable, while working in a unix environment is torturous without a reasonable interface. Thank you. +------------------ | Sam Sirlin | <1991Oct21.160654.16587@csi.jpl.nasa.gov> In article , weg@mace.cc.purdue.edu (Eythan Weg) writes: ]> 1) In J/PC version 3.3 I cannot fully load a workspace whose size is ]> 45000 bytes. It ends with workspace full. I may or may not be able Blame IBM/MS DOS. ]> 2 6 Sned 3.5 ]> domain error I get _. (indeterminate) on a Sun Sparc, which is much the same thing. ]> 3) Another unrelated problem is the interface to J on unix. Does ]> anyone has an improved version of Michael Berry's J-interaction mode ]> for Gnu emacs? I have a version dated 3/4/91. From that: If a lot of time has passed since March, 1991, you may be able to get a more recent version of this code by anonymous FTP from think.com in the file /public/j/gmacs/j-interaction-mode.el. ]> I find myself withis dilemma: J on pc seems to behave ]> fairly well except that the workspace limitations are not always ]> acceptable, while working in a unix environment is torturous without a ]> reasonable interface. I use J mostly on a Sun Sparc. With Xwindows the interface is not so bad since you can copy and paste previous lines, or edit script files in emacs in other windows simultaneously. I personally tend not to use the above .el as it stops xterm graphics commands (at least the first version did) and I use J often for plotting. I also store functions as script files rather than ws, as this seems more portable. *======================================== # Dyalog APL questions (basic data representation) +------------------ | J. Patrick Harrington | <7258@umd5.umd.edu> 7 Sep 90 I have recently obtained Dyalog APL for one of our Sun 4 computers, and it is indeed an impressive implementation, especially after limping along with a bug-ridden version of APL\11. One of the problems with APL is that it seems to be a universe unto itself, and little consideration is given to the possibility of interfacing it with other languages/data sets that may reside on the system. One great feature of Dyalog APL is that interaction possible using "Auxiliary Processors"; in particular, the 'unixfiles' AP lets you read a native unix file outside the APL workspace. I very soon found that I wanted to make some calculations based on some data sets - columns of floating numbers - which I had in non-APL files on the system, and I surely didn't want to type them in. Well, 'unixfiles' would read them in, but in the form of nested arrays of characters. I could disclose and decode the strings of characters to get numeric data - but then there were the '-' signs! Another AP called 'xutils' contains the function 'ss' which searches out and replaces strings. So we replace each '-' with the high minus, and the 'e's with 'E's. So I wrote a little function that reads in a named unix file and turns it into a APL numeric array. But it still hangs on the occasional '0.000E+00' it may find in the unix file. I would think that reading lists of numbers from files would be such a basic need that others must have solved this problem. Is there some neat way to do this? Another question for those who may be using Dyalog: Our printers are Apple LaserWriter II's, which isn't one of the supported printers. Does anyone have experience with this combination? +------------------ | Raul Rockwell | <11913@chaph.usc.edu> 11 Sep 90 02:00:47 GMT In article <429@kepler1.kepler.com> rjfrey@kepler.com (Robert J Frey) writes: >[...description of application deleted...] I would think that reading lists >of numbers from files would be such a basic need that others must have >solved this problem. Is there some neat way to do this? ... As far as doing it within APL itself, I can offer two suggestions: First, use 'ss' to make the substitutions, eg, '-' -> negative-sign, 'e+' to 'E', etc. then do an 'execute foreach' on the nested character string. Second, ... actually, it is not clear that any string substitutions need to be made. Simple character substitutions should be more than adequate for this kind of thing. For example, to change e to E, and + into 0, just adjust the ascii values of each e. In J, this might be expressed: m =. a. {~ (a. i. m) + ((-/a. i. 'Ee') * m='e') + (-/a. i. '0+') * m='+' Or, in a more standard apl, this would look something like: M <- []AV[ ([]AV i M) + ((-/[]AV i 'Ee') x M='e') + (-/[]AV i '0+') x M='+'] This technique can easily be extended to convert commas to whitespace, or whatever, minus sign into negative sign, or whatever. You could also consolidate the starting and ending characters into vectors, or whatever, and encapsulate the logic in some nice little package--if that pleases you. There is also the matter of implementation limits. Can you pull a megabyte file into memory and convert it all at once, or must you loop through it is smaller chunks? But as I remember, the original question was more about the details of the character conversion. *======================================== # J comment styles +------------------ | Raul Rockwell | Sam Sirlin writes: > I think your branch around initial comments won't stop the parser from > looking at the comment lines at the definition phase ... Yeah, you still need to be careful. It's just simpler to type. > On the other hand, I think any readable programming style should use > comments sprinkled throughout a program, and this would be contorted > using branching all the time. By making it cumbersome, J seems to be > designed to discourage comments. I think you're squashing some unrelated ideas together here. J does not provide an anomalous syntax for comments, but that doesn't mean comments need to be cumbersome. First off, it helps to have a few tools to write programs with. One technique is to use an editor to build your objects, and save everything in a workspace. Another is to build scripts which read objects in from standard input (that is, the script). Second off, there are quite a number of useful quoting techniques. The first of which is to organize your program carefully. Also, using descriptive names helps a great deal. Also, for some verbs, it helps to have a block comment at the begining (or end), to orient the reader. And then, you can always adopt a style where you have comments describing individual lines of a program (usually, you set off both the comments and the described lines with blank lines). And, finally, you can do "running narrative" tricks like: a =. ['step one'] here is a calculation b =. ['step two'] here is another I don't know if it is possible to come up with a "perfect" comment syntax (for example, in C you have to be careful when you divide by a number referenced via a pointer, and you can "accidentally" comment out large sections of code with no warning from the compiler). J's comment style has the advantage of making comments proper objects of the language (which makes the language itself somewhat simpler, and allows the user much more flexibility than some sort of pre-processing kludge). +------------------ | L.J.Dickey | <1991Apr29.152429.15070@watmath.waterloo.edu> In article rockwell@socrates. umd.edu (Raul Rockwell) writes: > > >J does not provide an anomalous syntax for comments, but that doesn't >mean comments need to be cumbersome. I wish it did. I like end of line comments, and find something like this useful: C =. ' 0 0 $ 0' :: '.x' [[NB. sws. this would now be C =. ' 0 0 $ 0' : 'x.' ]] for a comment marker, and works fine for many types of statements, for example simple data declarations, like data =. 2 3 4 C 'here it is' But for tacit function definition, it just will not work. I have not been able to find something to put at the end of a line like this: sumover =. +/ I would like to have end of line comments, like this, maybe: sumover =. +/ C adds them up. And I would prefer the above to this: sumover =. +/ C 'adds them up.' I really want the interpreter to ignore everything to the right of the comment flag. In line comments, like a =. 1 2 3 , }: 'hi there ' {: b =. 4 5 6 in versions 2.9 or earlier, or a =. 1 2 3 , [ 'hi there' ] b =. 4 5 6 as in 3.0 are swell, but just don't fill all the needs. [[NB. sws. NB. does fit the above needs well! ]] +------------------ | Sam Sirlin | <1991Apr29.181700.12298@jato.jpl.nasa.gov> In article you write: ]> I think you're squashing some unrelated ideas together here. certainly. The issue isn't really simple. ]> J does not provide an anomalous syntax for comments, but that doesn't ]> mean comments need to be cumbersome. I think it does. With lamp, you can put anything you want afterwards, such as ' )why not. I agree with L.J. Dickey that the generality to do this is desirable and useful. If language syntax controls what you can put as a comment, I would say that's cumbersome. The only way comments can be completely arbitrary is if they are anomalous language elements. I'd guess this is proved in introductory progamming language design courses. I don't know and don't have a formal proof (I'm an M.E.), but it sounds like an interesting logic problem. ]> First off, it helps to have a few tools to write programs with. One ]> technique is to use an editor to build your objects, and save ]> everything in a workspace. Another is to build scripts which read ]> objects in from standard input (that is, the script). If you don't use readable scripts that can be changed by some completely external editor, aren't you in trouble when the language changes (like 2.9 -> 3)? Can J 3.0 read a 2.9 ws? (I know this is another unrelated subject). ]> Second off, there are quite a number of useful quoting techniques. ]> The first of which is to organize your program carefully. Also, using ]> descriptive names helps a great deal. Another unrelated subject: J uses x. and y. for arguments. Undescriptive. One technique I sometimes use is to immediately set xlabel=. x. location =. y. or some such. I find this somewhat unappealing as it looks inefficient, especially if used in some inner routine (called by many others). A kludge. > Also, for some verbs, it helps ]> to have a block comment at the begining (or end), to orient the ]> reader. I agree. I do that. >And then, you can always adopt a style where you have ]> comments describing individual lines of a program (usually, you set ]> off both the comments and the described lines with blank lines). Another good style I agree with. ]> And, ]> finally, you can do "running narrative" tricks like: ]> ]> a =. ['step one'] here is a calculation ]> b =. ['step two'] here is another ]> Doesn't this look aesthetically unappealing? Two (or 3) comment characters? Looks kind of like a kludge to me. Especially if you have contractions, embedded quotes etc. which some comments will have. ]> I don't know if it is possible to come up with a "perfect" comment ]> syntax (for example, in C you have to be careful when you divide by a I don't like C's comments for the reasons you mention. On the other hand, I find APL's (lamp) perfectly acceptable. ]> J's ]> comment style has the advantage of making comments proper objects of ]> the language (which makes the language itself somewhat simpler, and ]> allows the user much more flexibility than some sort of pre-processing ]> kludge). One person's kludge might be another person's efficient solution. For example one language element (lamp) versus two or three([]'). I think that the designers of J took a "theoretical" approach rather than a "practical" approach. This leads to many advantages, but some dissadvantages. Comments are an important issue. One serious criticism of APL is that the code is "impossible to read." I think the criticism is somewhat undeserved since: - small sections of APL may in fact be much easier to read than equivalent sections of other languages due to compactness, - one can always choose to write readable code, for example deliberately separating things onto seperate lines, adding comments liberally... I'd rather have the freedom to do what I want instead of having the language impose readability ("structured languages") on me. J seems to me to be taking the other extreme, making it harder to add comments and write readable code. This is admittedly a subjective judjement. I'ts not a condemnation of J, as I still admire the language overall, and especially admire its availability. +------------------ | Raul Rockwell | 30 Apr 91 01:28:56 GMT Sam Sirlin writes: > With lamp, you can put anything you want afterwards, such as > ' )why not. perhaps that is an issue LinkJ is meant to address? (assuming it will be available).