199 points · by todsacerdoti · 5y ago · 102 comments
I did APL, which was fun, and easy. However in researching the language I came across some IBM accounting source code written in APL. It really clued me into how the language got such a following in HR/Finance applications. You got an array of everyones hours per day. Weekly total hours, pay, tax, medicare, etc, were all broken out in little calculative statements based on the array of hours. So rather than long strings of APL characters, there was just massive amounts of english and these little digraphs or trigraphs of APL for the calculative values.
I would honestly love a candidate to use some esoteric/legacy/wacky/niche language to spice it up.
If they can walk me through it that would be a Strong Hire in my book (assuming it actually works when I test it later).
Yeah I guess APL is kind of 'spreadsheets as a Real Programming Language', isn't it?
Many years later I came across it again in a financial modelling application where it worked well. Only problem was that there were (I think) only three people in the company who understood it. So it didn't last long as the risks / costs were just too great. Which I guess would be a typical scenario for many APL applications.
And in the end, I wonder if it is more readable than regex which is sometimes considered 'write-only', because reading it can be so time consuming. I know you wrote about the readability topic, but I don't mean 'can I read it', but rather 'How much effort takes it to read it'.
The syntax is very simple, there's nothing scary about special characters if you can get over your fear of them, custom keyboard layout is absolutely not required (I've never used a custom layout for APL or Japanese or Cyrillic or Greek or any other non-latin characters that I type on a keyboard). Dialects are a thing but Dyalog is such an obvious choice if you want to learn APL that I wouldn't even worry about the rest. (K is worth looking into for its own sake but I don't consider it a dialect of APL; J might be a dialect worth exploring but so far it didn't impress me much and I found it much harder to read than APL).
One more thing: I find that reading APL is easier than writing APL.
The second learning curve however is the much harder part, learning how to write APL 'idiomatically'. This is mostly true in any language though, especially one in a different paradigm.
so, while a considerably smaller language, it's like learning Chinese (for someone who uses a Western alphabet)?
7×3 ⍝ Dyadic × is multiplication
ׯ7 ⍝ Monadic × is 'direction', or signum (the sign, in our case). Thanks.
And looking at the output I can see: 21
¯1
Is it a typo or really -7 is becoming -1 for some esoteric reason that escapes my comprehension? ×-7
¯1
×7
1
×0
0See 5.3.5 for what that bit of code represents. The box is, in fact, being displayed correctly.
The xkcd "light saber" thing made lisp seem appealing to me a few years ago, but after a brief intro to the array languages, now I think they're much more deserving of that comparison.
I think in some way anyone's first language will spoil them for whatever that language is best suited for. My "first" language was Z80 assembly, because I wanted to make games for my calculator (I ended up writing just one[0], also "first" because technically my first was TI-BASIC of course). I've missed feeling like I directly was speaking "to the metal" ever since. Don't get me wrong, I'm super-happy with the high-level languages I've used since, but whenever I have to wrangle efficient code out of JavaScript there's some (probably misplaced) nostalgia for when I didn't have to worry about whether or not the JIT will kick in or not.
[0] https://www.ticalc.org/archives/files/fileinfo/328/32817.htm...
Even throwing away the “executable by a computer” part of APL and only considering it as a notation, APL can be powerful. Iverson gave a lecture, which was published as _Notation as a Tool of Thought_ [1] that contains a good discussion of what exactly makes a given notation “good”.
[0] https://web.archive.org/web/20141027152546/http://www.softwa...
https://twitter.com/nathrune/status/1423703525612212232
That actually sounds like quite a powerful addition to Snap!
Maybe lisp was in that club too but clojure made it mainstream again, by my horribly inaccurate, unscientific and probably wrong reckoning.
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!
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."
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.
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.
I imagine writing an APL expression that expands to, say, 100 lines of C++ :-p
K is another array language which has a proprietary implementation. Tcl is a relatively popular proprietary language.
Wikipedia says Tcl is an open source language, did you mean a different Tcl?