"More operators? It's getting as good as APL!" -- except that it still
falls way short in this respect. I'm serious; APL does *not* have too many
operators. It does have too little structure.
Frank Adams ihnp4!philabs!pwa-b!mmintl!franka
Multimate International 52 Oakland Ave North E. Hartford, CT 06108
The primitive functions in APL correspond roughly to C operators *and* the
entire runtime library. I agree that APL does not have a problem there.
APL has its own character set; C is restricted to a subset of ASCII. The
size of the alphabet is not a serious problem since new operators in C may
be multi-character; however, this may make them less mnemonic. (Of course,
some of the APL characters are not all that mnemonic either: "x" for signum
is a good example.)
The reason APL can deal with having so many primitives is that they all have
the same precedence. Adding that many operators to C would be a disaster.
You say APL has "too little structure". If you mean things like "while" and
"if", I think they may be unwelcome. Put in a "while" loop, and people will
start using it to implement a matrix multiply. (For those who don't get it,
APL has a builtin matrix multiply, "+.x".) The language doesn't need much
program structure, because it has data structure in its place.
Now, I *would* like to see some improvement in the data structure. It's now
practically impossible to write a function which expects, say, three string
(character vector) arguments. I like the grounded tree model, myself, as a
fix for this. Also, APL is *severely* in need of *variable declarations*!
Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint
*** Please restrict followups appropriately! {net.lang.c|net.lang.apl} ***
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.
People can write a matrix multiply using go to right now. There is no cure
for idiocy, and only one for ignorance.
>Now, I *would* like to see some improvement in the data structure. It's now
>practically impossible to write a function which expects, say, three string
>(character vector) arguments. I like the grounded tree model, myself, as a
>fix for this. Also, APL is *severely* in need of *variable declarations*!
I had both program and data structure in mind when I made that statement.
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.
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.
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!
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.
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.
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"
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."
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.
- Arch D. Robison
University of Illinois at Urbana-Champaign
>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.
syn...@looking.UUCP waterloo, ontario, canada
watmath!looking!syncro (519) 884-7473
"These opinions are solely mine, although even I would like to deny them..."