Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!bu.edu!wang!wdr From: wdr@wang.com (William Ricker) Newsgroups: comp.software-eng Subject: Re: AvAaA: Try APL descendant "J" Message-ID: Date: 22 May 91 16:43:24 GMT References: <16281.281f708f@levels.sait.edu.au> <16309.282b0e06@levels.sait.edu.au> <16348.2833a96e@levels.sait.edu.au> Organization: Wang Labs, Lowell MA, USA Lines: 120 xtbjh@levels.sait.edu.au (behoffski) writes: >How close does J get to adjectives, Quite close if you're careful. There were some very literate APL programs back in the heyday of mainframe timesharing services; Rose's book had some, as I recall. The regularity of the J grammar makes it even easier to design plug-and-play domain specific languages than it had been in APL of yore, and the expressiveness of the built-in adverbs and conjunctions makes compounding simpler than in Forth, I think. I'm afraid generarl purpose analysis of compound nouns, such as the examples given, however, belongs more in comp.ai.n-lang (natural language) -- context really affects how we as humans interpret these phrases. However, we can build J functions which act as english adjectives in the sense of discussing properties and selecting subsets based on properties that will in limited domains compose nicely. > e.g. "all positive elements of array" -- this is a simple enough example I can do it myself without appealing to the COMP.LANG.APL folks for help. ****** First, I'll define synonyms in english for J's key operators ravel=. , **** list the elements of any array -- reduces dim to 1 copy =. # **** select sub-array by selectively copying items; e.g., 1 0 2 0 3 0 0 copy 'abcdefg' acceee ******* Now I'll use the Currying conjunction & to define the concept ******* of a positve number as any number greater than zero. positive =. > & 0 positive 5 1 positive 0 0 positive _3 **** negative 3 ******* applied to an array, it yeilds a binary string A =. _3 + i. 7 A _3 _2 _1 0 1 2 3 positive A 0 0 0 0 1 1 1 ******* that can be given to copy (positive A) copy A 1 2 3 ****** the ~ adverb will reverse the arguments, so we can dispense with ()'s A copy~ positive A 1 2 3 ****** now we define elements to be just ravel if given only right argument ****** and to expect a boolean vector on left of same length as the right ****** which selects which elements of right to keep. elements =. 'ravel y.' : 'x. copy~ y.' elements A _3 _2 _1 0 1 2 3 A elements positive A 1 2 3 (positive A) elements~ A ***** here, the ~ adverb requires ()'s 1 2 3 ****** we can use the (fg) and (gfh) forms to make a compound verb. ****** (as with the Currying adverb & above, this connects to Combinator ****** theory!) ****** if f is monadic, '(fg)y' is just f(g(y)), which is 'f g y' in J syntax. ****** boring but sometimes useful ****** if f is dyadic, '(fg)y' is defined as f(y,g(y)) or 'y f g y' in J ****** and '(gfh)y' as f(g(y),h(y)) or '(g y) f (h y)' in J ****** and 'x(gfh)y' as f(g(x),h(y)) or '(g x) f (h y)' in J (elements positive) A ***** = (positive A) elements A 1 2 3 QED. Getting the coordinatees of the postive elements rather than their values would be equivalent, but I'm not upto it before lunch. >or "all diagonal elements"? diagonal would have to be a function which returned the identity matrix of the same shape ([1 0...0]...[0...0 1] ) (*clipped if rectangular? or undefined? your choice!*). Same elements should work in both cases, but you'd probably need to add a conjunction or adverb to handle squeezing a 2dim array to a 1 dim array in the process; whether this goes in the definition of elements or in the use, I'm not sure. (I'm getting hungrier.) > How would you go about implementing a binary tree, > and how would you then operate on the "leaf nodes"? The new APL's, including J, have boxing operators to encapsulate arrays into new atoms. This allows for ragged arrays and heterogenous arrays and nested arrays. So you can build a binary tree as a recursive structure of 2x1 arrays (3x1 if you want tags!) which bottom-out into something else as leaf-nodes. I haven't thought about this hard, but it is obvious to me that one could easily implement in J the classic Lisp MAP*** functions -- which collect a list of, or return a list of results of appling a function to, all the **** fragments of a structure: J has both recursion and the ability to pass functions as arguments, so higher order functions are no problem. > How easy is >it to change the implementation of an operation without changing the >original program specification? A very good question. The cheap answer is it always depends on whether anyone cheated when using the operation by assuming somthing beyond the specification. The developers of J have considered that mathematicologicians might wish to engage in formal manipulations of J programs and so support a combinator style of definition (used in 'positive' above) as well as the more textual (in 'elements'). J itself is constructed by self-specification. So the culture is there. However, I wouldn't say that the modularity of J is sufficient yet to really support mechanism hiding to the extent that you can have any confidence that only the specification is being relied upon by callers. Boxing itself is a great data-hiding mechanism though -- make the record or whatever an Atom that can only be sensibly unsealed by the module sealing it, and everyone else can just toss it around wherever. Your choice if you have a standard to wrap all Boxed Atoms with a label/tag (roll-your-own object oriented?) or to just have the intended type obvious from context, which takes different discipline (which in a strictly typed language would have been supplied). -- /s/ Bill Ricker wdr@wang.wang.com "The Freedom of the Press belongs to those who own one." *** Warning: This account is not authorized to express opinions. ***