by civilized · 5y ago · 0 comments
APL seems to be designed for people who place an extremely, extremely high weight on code golf-level terseness. IMHO, terseness isn't the be-all, end-all of comprehensibility. I'd rather just use the words "max" and "min" than learn redundant special symbols for the same that save me a couple characters.
The paper kicks off with a quote by George Boole: "That language is an instrument of human reason, and not merely a medium for the expression of thought, is a truth generally admitted." Having a terse language in itself can lend itself to thinking about problems and playing around with them in your head more effectively. I know when I'm thinking about an algorithm to be implemented in something like java there isn't room for all the boilerplate in my head. Stuff like "public static void main..." gets fuzzed out when thinking about a solution, to be replaced the idea of "place where main method is".
I like the idea of boiling down useful abstractions to the most simple symbols we can manipulate mentally, to be able to fit the most possible high level abstractions in our mind at the same time. This should make it possible to be able to play more with constructing solutions. Never feeling particularly locked down because you have to manipulate a lot of syntax and curly braces to implement or think about an idea. That you only have to switch around a few symbols for a change in semantic meaning.
Having never learned something like APL myself, I can't speak personally about the effectiveness of this idea.
Personally, I much prefer the APL for a few reasons. If I tell you that +/ is sum, you can reasonably guess what product is. (×/).
However, in q, if I tell you 'sum' is sum, can you guess what product is? Well, maybe. But it's prd. Would you have guessed that first try?
This seems like it might not be that important, and obviously to the q developers it isn't. But it is a consideration that logically leads to terse symbols.
If you had to write reduce(plus, arr) every time of course you'd rather have a word for 'sum', it's only because of the symbols that let you decompose larger problems into the smaller primitives without ending up with more verbose code than other languages.
Additionally, words that describe the inherent function makes reading the source A THOUSAND TIMES easier.
If A new developer sees the word max/min/sum, they can almost assuredly guess the meaning versus a random pictograph. And even after learning that ‰ means reduce (for example), it's just one more thing that I have to remember.
Sure. I don't doubt this. However, if your language is good enough, it's unnecessary. I don't want to rely on an IDE for something as straightforward as taking the product of a list of numbers.
> words that describe the inherent function makes reading the source A THOUSAND TIMES easier
If your functionality is complicated, this is probably true! No one's saying not to use descriptive function names in APL. You absolutely can (and probably should) for things used multiple times more complicated than a couple of symbols. However, in general I don't think this is true. Have you tried?
With regards to guessing the meaning, you do have a good point. If you show someone some APL, and they've never seen it before, it will most likely be completely unreadable, unless they've defined some sort of custom DSL. It doesn't mean they can't pick it up though.
Comparing q and APL again, if I see the word 'raze' in q, without knowing what that is already (looking at docs etc) it's basically impossible to guess. In APL, that would be ,/ instantly readable as 'reduce by concatenation'.
> it's just one more thing that I have to remember
Yes, you'll have to remember the symbol for reduce. But you won't have to remember the word for sum, product, any, all, raze, max, min...
Seems worth it to me!
In contrast, in APL, once you know about reduce, there's just one way any of those could be written, and it's obvious. And after you learn about scan (cumulative reduction), you also know the cumulative version for all of those!
I disagree. Using add instead of +, for example, does not make code more readable at all, on the contrary.
a*(b+c) = a*b + a*c
Let's make that "more readable": equals(multiply(a, sum(b, c)), sum(multiply(a, b), multiply(a, c)))
It's not about the terseness, I just don't see a clear pattern using the "readable" notation. But it is obvious when using symbols.You can find another interesting example at: https://wjmn.github.io/posts/j-can-look-like-apl/
It feels like the Zen of APL is "symbols are a freaking great idea, let's do more of those!" when intellectual communities that are heavy on symbolic manipulation are generally quite conservative in the introduction of new symbols... let alone the dozens that APL introduces.
To each his own and all, but APL might have to content itself with a small group of devoted fans.
Very clever people have been working in array languages for more than 60 years, and there is a set of around 20-30 primitives that all of them agree are worth to have. Depending on the array language of choice, there are another 10-40 primitives more. Symbols have double use (monadic and dyadic), so that makes a total of 20-40 symbols to learn, and you already know many of those (+-×÷=<>, and probably a few more).
To each his own indeed. But if you haven't, I would suggest you to give it a try. It makes much more sense once you start writing code.
(a times (b plus c)) equals ((a times b) plus (a times c))
would be a fair comparison, which is much more readble than =(*(a, +(b, c)), +(*(a, b), *(a, c))) (a times (b plus c)) equals ((a times b) plus (a times c))
easier to read than a*(b+c) = a*b + a*c
?You've written as though using symbols instead of names comes at an extraordinary cost. Having used both I don't think this is the case (and it's the conventional languages that force you to use words; you're free to define reverse ← ⌽ in APL but usually not the other way around). If you want to read more about this perspective, you could check out my page "What is a primitive?" discussed on HN yesterday: https://news.ycombinator.com/item?id=28060423
One advantage is that long expressions might fit in one line, but that's about it.
I mainly use Scala, which allows to use symbols like ← ⌽ as well and quite a few libraries do that - but I found unless it's a very commonly used symbol, it's not helpful for productivity.
To be clear, you do think there's an advantage to using symbols for very common operations? APL doesn't have all that many primitives (~60 symbols), and most would fit this requirement. Here's Alan Perlis[0]: "The large number of primitive functions, at first mind-numbing in their capabilities, quickly turn out to be easily mastered, soon almost all are used naturally in every program — the primitive functions form a harmonious and useful set."
The programming community has been extremely open-minded to revolutionary new approaches. So very many have gained at least a foothold and a small group of devotees, from LISP to Haskell to Forth to APL. But none of these languages have built communities of a size and productivity to match Python or C or the many other highly successful Algol-family languages. This despite the fact that some of these off-the-beaten-path languages, especially LISP, have a long history of being used as teaching languages.
So why hasn't APL taken off already? Surely there must be a more thoughtful answer than "people are Philistines". Perhaps both APLers and LISPers greatly underestimate the challenges of adopting new symbolic notations that are very different from what they're used to in written language and mathematics. Maybe for the average technical person, the cognitive costs are much greater and the benefits much less than they seem to the average APL or LISP fan.
I can only speak for myself, and I know I'd be confused seeing code that says (enclose bind grade-up index right), but when I see it spelled in APL as (⊂∘⍋⌷⊢), I will immediately recognize it as sort.
It really does feel similar to the difference between "es you es aitch I" and "sushi".
I don't need to spell out every symbol, that just makes it harder to pattern-match and see the meaning.
And I had read that comment! It just didn't register at all when I read that comment; even though I read it word by word, I did not realize that he also wrote the sort train (until I read it again now and converted to symbols in my head). Yet I would have immediately recognized it had I seen it written as APL symbols.
Visual pattern matching can be strong. (It's what allows you to recognize and read words that you do not know how to spell correctly.)
For instance, | 3 2 1 0 is read as "reverse" the array "3 2 1 0". So | 3 2 1 0 gives you 0 1 2 3.
It certainly seems easier to read than "reverse 3 2 1 0". – which assumes your a fluent english speaker.
APL uses custom glyphs
J uses symbols from an ASCII keyboard - its a big set of primitives
Q from Kx systems uses words.
The conceptual basis for the languages is very simple. As others have said - your experiences will guide where you feel most comfortable.
If you want something APL-like but without the symbol heavy nature, the nearest is going to be languages like Haskell that similarly promote tacit programming but without quite as heavy a reliance on symbolic notations, or descendent languages of APL like q.
⍳+⊢ 3 ⍝ the first 3 numbers
1 2 3
it behaves differently from the same thing in parens shown below, which triggers a function train pattern and slightly breaks the right-to-left execution by making the data able to feed into two functions, not just one. In the below code the 3 is pushed into ⊢ on the right which echoes it unchanged but it also jumps over and is pushed into ⍳ on the left to make the first three numbers 1 2 3, and these two results become (1 2 3 + 3) and the whole thing makes 4 5 6: (⍳+⊢) 3 ⍝ 3 plus the first 3 numbers
4 5 6
It's not the parens which make the difference, assigning it to a variable to make a named function also does it: f ← ⍳+⊢
f 3
4 5 6
Point being, there's something semantically meaningful happening but it has no symbol to turn into words. It's not the proximity of the functions being bunched together even, it's roughly an odd number of functions separated from their argument(s) but with some edge cases. The text editor would have to be parsing APL to detect it, and I don't know how it would describe what's happening in useful words. "iota plus self_right" might still let you recognise three things together, but does "enclose bind grade_up index self_right" look like a function train? Does "It's easier to spot the pattern with symbols, it's easier to have the pattern exist at all in a symbols based language.When the Dyalog IDE can show you:
+,-,×,÷
┌─┼───┐
+ , ┌─┼───┐
- , ┌─┼─┐
× , ÷
to explain how the train is being interpreted, what does the text version of that say? if (username == "alice") {
results[5] = true;
}
into this: if username valueequals STRINGaliceSTRING begin
let results index 5 be true stop
endif
because symbols are incomprehensible, words are much clearer, and you don't care about saving "a couple of characters" and you don't like codegolf. Would you use it? If not, why not? How do you know the amount of symbols you use is the perfect amount and not merely the amount you are habituated to?> "Why not give the symbols more descriptive names and let people use those names
For the same reason almost nobody wants {} to be BEGIN/END; the symbols are so ingrained, so well understood, so automatic and habitual that there's no benefit to trying to turn them back into words. Why not move towards doing the same for other common operations? Once you've used ⌊ as floor and ⌈ as ceiling, Math.Floor() feels like a drag. Once you're familiar with 4↑list to get the first 4 items, list[0..4] is a drag and it has more symbols! list.take(4) has more symbols and is no clearer. How do you stop a forever-expanding proliferation of symbols? I don't know, but APL seems to have done a surprisingly good job of general purpose computing in under ~80 symbols which has hardly grown in 70 years.
> "APL seems to be designed for people who place an extremely, extremely high weight on code golf-level terseness."
Would you be surprised that this is valid Dyalog APL for a function to find the highest value in an array of positive integers?
result←findMax data
max←0
:For i :In data
:If i>max
max←i
:EndIf
:EndFor
result←max
then findMax 5 1 2 3 5 6 3 1
6
Dyalog has keywords, classes, namespaces, methods, libraries, and they get laughed at because who wants :EndFor . It's a bit of a PR issue - if you head to APL it's largely because you like golf, because if that's not what you want you may as well use Python/etc. But once you get there even if APL remains too opaque to use for everything it becomes annoying to know a short way to express what you want that you are comfortable with and have to laboriously boilerplate it out in another language with many lines, and have those lines contain more symbols into the bargain. And we say that one of the hard problems is "naming things", symbols and tacit programming can help avoid putting a name to variables that only hold some intermediate state you don't actually care about but need for the next couple of lines.> Who on Earth has to literally write a loop in the middle of their source code to find the max of a bunch of numbers?
People that uses JavaScript or other language which have a really small standard library.