Xref: utzoo comp.lang.functional:431 comp.lang.apl:511 comp.lang.misc:5491 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!chaph.usc.edu!usc.edu!news From: news@usc.edu Newsgroups: comp.lang.functional,comp.lang.apl,comp.lang.misc Subject: Re: A preliminary review of J Summary: Substance over style Keywords: Oopps Message-ID: <12075@chaph.usc.edu> Date: 21 Sep 90 01:29:32 GMT References: <12061@chaph.usc.edu> Sender: news@chaph.usc.edu Followup-To: comp.lang.functional Organization: University of Southern California, Los Angeles, CA Lines: 95 Nntp-Posting-Host: alcor.usc.edu In-reply-to: news@usc.edu's message of 20 Sep 90 10:55:05 GMT Originator: news@alcor.usc.edu Shortly after I made the earlier posting <12061@chaph.usc.edu>, I realized I had made several mistakes, including a couple program bugs. First off, I should have said first =. {. and rest =. }. as each of these functions take only one argument, and giving them two arguments only confuses the matter. Secondly, I should have explained my notation a little better. Explanation follows (long) Lines that were indented three spaces, such as o =. 0 0$'' were lines intended to be typed into the J command line interface. Unindented lines which immediately followed were usually the function results (except where I was using the 'read' function.. there they indicated input to be read. Also, I mixed in free text, but I hope that was obvious). Second, the J lexical analyzer would parse o =. 0 0$'' like this: .-.--.---.-.--. |o|=.|0 0|$|''| '-'--'---'-'--' Generally, anything followed by a . forms a two character token. Non alphabetics followed by a : also form two character tokens. After than, numeric lists (where each element begins with a digit, such as 2e or 4j) formed into tokens, as are ' delimited character strings, and fairly typical alphanumeric symbols. =. indicates local assignment $ y gives the shape (dimensions) of y x $ y returns a new array containing array cells from y, arranged with the dimensions given in x !: is the 'system call' interface (and is syntactically a conjunction) I forget whether I mentioned that adverbs only take their arguments from their left, and conjunctions take an argument on both the left and right side. Also, because of priority, adverbs and conjunctions can take either verbs or nouns as arguments, while verbs can only take nouns as arguments. x }: y returns x :: is the generic definition conjunction x , y catenates x and y to form a longer list & is a conjunction that sticks two verbs together to form a single verb, or sticks a noun and a verb together to form a verb. e.g. (-&3) 4 would return 1 {. y returns the first array cell in y }. y returns all array cels but the first in y y. is the right argument passed to something defined by :: x. is the left argument incidentally, in a definition like string1::string2, the string1 definition is used when there is only one argument available, and the string2 definition is used where their are two nouns available. (and a character matrix or a list of strings would work here just as well as a simple string). =: is for global assignment. I used this for 'set', because local assignment is trickier (you have to evaluate it in the right context), and the feature that I would have used to make this work is not implemented in version 2. x ; y will 'box' y, if it is not already boxed, and it will box x, and then it catenates the boxed version of x onto the front of y. Although I didn't mention it, if you just want to box a single object, you can do it with (< y). Boxing is roughly equivalent to C's & operator--you are effectively taking a pointer to the object. Unboxing, which may be done with (> y) is roughly equivalent to C's * operator, except that if y is an array of boxed objects, the newly unboxed elements are padded to make them all the same size, and the result is a new array with extra dimensions on the end, to hold these new elements. I could go on, but I ought to stop somewhere...