kwh@bentley.UUCP (KW Heuer) (05/27/86)
In article <1477@mmintl.UUCP> mmintl!franka (Frank Adams) writes: >I disagree. "if/then/else" would be very useful in APL. You wind up >using go to (->) instead. This is bad for the same reason it is bad in >other languages. The data structuring somewhat reduces the need for such >things, but not all that much -- particularly for complex applications. Suppose there were no MIN primitive, and we wanted to implement it. The straightforward approach would yield (uppercase denotes APL symbols) DEL z IS x min y [1] GOTO (x > y)/4 [2] z IS x [3] GOTO 0 [4] z IS y DEL However, one can also write DEL z IS x min y [1] z IS ((x LEQ y) MULT x) + (x > y) MULT y DEL (or variations thereon), which I would consider attrocious programming in a conventional language, even in a dialect of BASIC that has the same rules. (No flow control except GOTO, but relational operators yield a value.) But in APL, the second method is preferred, because it uses scalar primitives only -- and hence will work properly when given two compatible arrays. I just wanted to show that it's not always appropriate to compare APL to a conventional language, and that if/while is often the wrong way to think about a problem. Of course, there are real examples where flow is necessary, which currently require a GOTO. The APL equivalent of "do this block n times" is especially ugly. I don't know if adding flow control is a good idea or not. (Some would argue that the language is so hard to read that proper flow control is irrelevant.) I think that it's probably better to graft the useful features of APL (terse high-level array manipulations) into another language than to try to fix APL. >One advantage of a proper implementation of variable declarations is that >one would be able to define a function as operating on, say, two scalar >arguments; if invoked with two arrays of the same dimensions, it would >automatically be called for each corresponding pair of scalars. Yes. It would also make it much simpler to write a compiler; currently when an expression like "foo - 3" is encountered, the interpretation of the "-" depends on the (unknown) arity of "foo": "foo() - 3" if it's niladic (or a variable), "foo(-3)" if it's monadic, run-time error if it's dyadic. There are compilers for APL, but they have to "guess" -- and have a backup plan in case the guess is wrong. Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint
ljdickey@water.UUCP (Lee Dickey) (05/28/86)
> >I disagree. "if/then/else" would be very useful in APL. You wind up > >using go to (->) instead. This is bad for the same reason it is bad in > >other languages. But APL already *has* the "if/then/else" in direct definition. The beauty of direct definition is that if your off-the-shelf micro APL does not have it built in, you can easily implement it using Standard APL. I think that the power of APL is in the notation, the language itself. Someone has said that Iverson invented the language as a tool with which to express algorithms, and that he did not at first expect it to be implemented as an interpreter. When some engineers discovered that the entire 360 architecture could be described in one page of APL code, they became excited about APL and decided to implement the language as a development tool. The name of the first APL was APL\360. In APL, "\" is the "expand" function. APL\360 certainly did expand the 360!
franka@mmintl.UUCP (Frank Adams) (05/30/86)
In article <400@water.UUCP> ljdickey@water.UUCP writes: >> >I disagree. "if/then/else" would be very useful in APL. [Frank Adams] > >But APL already *has* the "if/then/else" in direct definition. The >beauty of direct definition is that if your off-the-shelf micro APL >does not have it built in, you can easily implement it using Standard >APL. Could you explain what you mean by this? What is "direct definition"? Frank Adams ihnp4!philabs!pwa-b!mmintl!franka Multimate International 52 Oakland Ave North E. Hartford, CT 06108
ark@alice.UucP (Andrew Koenig) (06/02/86)
>Could you explain what you mean by this? What is "direct definition"?
Direct definition is where you type
identifier: expression
and that defines a function named "identifier." Any variables
assigned in the expression are made local. Arguments are referred
to by the alpha and omega symbols for left and right arguments,
respectively. For a monadic function you can use all alpha or all
omega. So:
SQRT:alpha*0.5
You can also write
identifier: e1 : e2 : e3
where e1, e2, e3 are expressions. This means the value of the function
is e1 unless e2 is true, in which case it's e3. Thus:
FACT: alpha x FACT alpha-1 : alpha=0 : 1
Note that colon is not a function -- it effectively has lower precedence
than function symbols.
ljdickey@water.UUCP (Lee Dickey) (06/02/86)
> Could you explain what you mean by this? What is "direct definition"?
The concept of direct definition of APL functions was invented by
Dr. Kenneth Iverson, the inventor of APL (now working with I.P.Sharp
Associates in Toronto). There are two general forms of definition.
They are
fun : expr
fun : expr_f : cond : expr_t
Direct definition always creates a function that returns a result. For
the first form, the value of the result is the value of the expression "expr".
For the second form, there are two possibilities, depending on the value of
the condition. If "cond" is true, the value of the result
is the value of "expr_f". Otherwise it is the value of "expr_f".
Functions defined either way can be dyadic, monadic, or niladic.
A dyadic function (one with two variables) is defined if both the symbols
"a (alpha) and "w (omega) are present in the condition or the expressions.
for the variables. A monadic function (one variable) uses the
"w but not the "a . A niladic function (no variables) does not
include either the "a or the "w .
Here are two simple examples, written for a simulator. The function
that simulates the Direct Definition is called "ddef" and it accepts
a character string. (On a system that has real direct definition,
the "ddef '" and "'" are omitted.)
ddef 'plus: "a + "w '
2 plus 3
5
Here is the second example. It shows a uses of the second form,
creating the mathematical FACTORIAL function.
ddef 'fact : "w "x fact "w -1 : "w =1 : 1
fact 1
1
fact 3
6
fact 4
24
fact 5
120
Here the "x stands for APL multiplication. Sorry about the need
for escape sequences.
Both of these example are dyadic; you can have 4 other types, in addition
to the two types given above.
ian@wcwvax.UUCP (Ian Kemmish) (06/03/86)
>. . .. "if/then/else" would be very useful in APL. You wind up >using go to (->) instead. This is bad for the same reason it is bad in >other languages. The data structuring somewhat reduces the need for such ^^^^ ^^^^^^^^^^^ >things, but not all that much -- particularly for complex applications. When APL was all I knew, I used to think it had data structures, and that nested arrays, when they eventually arrived, would be even better. Then I started playing with Lisp and Smalltalk, and I began to get suspicious. I started calling what APL had "data aggregates". Now I earn my bread & butter playing around in C, I *know* that APL doesn't have structured data! I don't think I could possibly go back now. What I want to know is, am I a lone voice crying in the wilderness, or do other people who've moved on from APL feel the same way?? Disclaimer: I'm not out of touch: I have APL on my PC at home, but I only ever use it for the screen editor; I have just helped port a groovy modern APL onto our MG-1 workstation product, and I only ever use *that* when the pop-up calculator runs out of steam. Ian Kemmish ____ \ \ \ \ / Whitechapel Computer Works Ltd. \ /\ \ /\ / 75 Whitechapel Road \/ \___\/ \/ London E1 1DU "Makers of the fastest (and slowest) workstations in Britain"
ark@alice.UucP (Andrew Koenig) (06/03/86)
> For the second form, there are two possibilities, depending on the value of > the condition. If "cond" is true, the value of the result > is the value of "expr_f". Otherwise it is the value of "expr_f". Incidentally, I've never seen a clear definition of the meaning of "true" in this context. When I implemented a direct definition function, I decided that "true" meant "has no zero elements." This means that the null vector is "true."
franka@mmintl.UUCP (Frank Adams) (06/05/86)
Thanks for the description. This wasn't around back in '76, when I was writing APL for Sharpe. The concept is interesting and useful. It certainly eliminates the need for some if/then/else uses. I still think a genuine if/then/else would be a valuable enhancement to the language. Some sort of loop construct would also be valuable. Frank Adams ihnp4!philabs!pwa-b!mmintl!franka Multimate International 52 Oakland Ave North E. Hartford, CT 06108
robison@uiucdcsb.CS.UIUC.EDU (06/07/86)
I've felt the same way. Now for a question: Suppose you did want to add C/Pascal style structured data to APL. How would you do it? What new operators or functions would be necessary? I've been working on an FP implementation that has exactly the same problem: ``data aggregates'' which are not really structured. It's easy to group data into lists to simulate records, but the lists don't have field names, so type-checking and legibility both suffer. - Arch D. Robison University of Illinois at Urbana-Champaign
syncro@looking.UUCP (Tom Haapanen) (06/10/86)
In article <798@wcwvax.UUCP> ian@wcwvax.UUCP (Ian Kemmish) writes: >When APL was all I knew, I used to think it had data structures, and that >nested arrays, when they eventually arrived, would be even better. > ... >Now I earn my bread & butter playing around in C, I *know* that APL >doesn't have structured data! I don't think I could possibly go back >now. > >What I want to know is, am I a lone voice crying in the wilderness, >or do other people who've moved on from APL feel the same way?? When APL was all *I* knew (actually APL and FORTRAN), I thought that the arrays were quite sufficient for keeping data around. You'd have a bunch of arrays for keeping all the information about a set of items. Arrays of records? What? Linked lists? Who? And yet, after having been converted to C (and to Pascal and WSL), I spent last summer programming a large project in APL. Oh, I missed the data structures, but you can manage without them. It's very easy to insert elements into the middle of an array dynamically, and nested arrays allow you to keep different types of data objects in one array. Alas, you can't refer to elements by name, although using 'constants' to do indexing is possible. I felt a bit crippled going back to APL, but, then, there was that feeling of power, being able to manipulate matrices with a single keystroke! -- \tom haapanen looking glass software ltd. syncro@looking.UUCP waterloo, ontario, canada watmath!looking!syncro (519) 884-7473 "These opinions are solely mine, although even I would like to deny them..."