J Notation as a Tool of Thought
October 11, 2020 10:57 AM   Subscribe

Kenneth Iverson's 1964 language, APL, won him the Turing Award. His award lecture, Notation as a Tool of Thought, argued that better notations would lead people to deeper insights about mathematics. [...] I'd like to show how some of Iverson's notations lead to a better appreciation of what we can do with programming languages. posted by smcg (20 comments total) 19 users marked this as a favorite
 
I remember encountering J in my Computer Science course in the 90s. It was one of the more impenetrable languages there. I don't think I ever learned what a gerund was in J syntax.

I encountered it again a few years ago at a Curry On conference (which was theoretically about programming languages and paradigms in general, though in practice had a Haskell/Scala slant).
posted by acb at 11:22 AM on October 11, 2020


It seems like a step backwards from APL, notation-wise. It seems like typing $i and getting back the iota symbol (and so on) wouldn't be a difficult preprocessor to write. J sacrifices readability for easier data entry.
posted by CheeseDigestsAll at 12:11 PM on October 11, 2020 [1 favorite]


Ah Notation as a Tool of Thought, or as I sometimes call it, As He May Think.

I haven't written any J, but about a year ago I wrote a PowerPoint-like program in APL so that I could give a presentation at work with my IBM 5100. It works, but you need a patient audience.

@CheeseDigestsAll: I don't know, but maybe you could accomplish the same thing with font ligatures, the same way Cascadia Code does it for operators like -> and other common sequences.
posted by tss at 12:53 PM on October 11, 2020 [2 favorites]


Oh, and with regard to Notation: when I was typing it into my 5100, I found a typo in the definition of the f9 function in Appendix B. Compiler from Direct to Canonical Form. Given the sheer, practically limpid clarity of APL code it is fairly straightforward to spot, so I won't bother pointing it out here.
posted by tss at 12:57 PM on October 11, 2020 [5 favorites]


The Julia programming language makes full use of Unicode and its IDEs convert TeX notation to corresponding notation. I think Julia would feel very comfortable to someone who has programmed in APL.

Speaking of which, APL was my first programming language, if you don’t count programmable calculators. I was fortunate to be able to take a class on it in sixth grade and my jr high school had one of those funky IBM Selectric terminals to dial into the mainframe that ran the APL interpreter.
posted by sjswitzer at 1:16 PM on October 11, 2020


APL is notorious for being very terse. Instead of descriptive names, most functions (“verbs”) are single characters....To further terse things up, every symbol represents both a unary function (a monad) and a binary function (a dyad).1 While * y gives the sign of y, x * y is multiplication.......

...This drives people away from APLs ...

You think?

.....and leaves the deeper elegance undiscovered.
Darmok, his beard unstroked.
posted by thelonius at 1:35 PM on October 11, 2020 [6 favorites]


Looking at the example that tss posted, it makes me think of my half-baked theory that math would be easier to learn if mathematicians used good variable names. Software source code is much easier to understand if the developer uses good variable names. When a developer starts to try to imitate a mathematician, readability immediately drops. Perhaps much math isn't hard so much as it is hard to read.
posted by clawsoon at 1:52 PM on October 11, 2020 [3 favorites]


I wish the author had given more than a footnote to NumPy / Julia / Matlab. Most of the semantics discussed here are available in NumPy with a friendlier syntax and larger ecosystem. I'm completely sold on array-based programming, but so many APL articles focused on the advantages over scalar languages instead of the advantages over other array languages.
posted by scose at 2:52 PM on October 11, 2020 [1 favorite]


Julia's notation for operating on arrays is delightful. And you can pick it up pretty quick compared to J partly because Julia is secretly a Lisp and not an APL derivative at all.
posted by BungaDunga at 3:37 PM on October 11, 2020 [1 favorite]


Metafilter: Morally it behaves as an array of one element except in very niche circumstances.

I like the idea of treating everything as operations on arrays and I came up with ways to take it further and further until I realised that I was reinventing Lisp. Also, the idea of using funny symbols to represent operations but then overloading them is such BS.
posted by Joe in Australia at 3:58 PM on October 11, 2020


I sorta wish I knew more APL, I like its gist. I had hoped that one of the links would be that thinkpiece once read about how {+/ω÷ρω} is pretty much the definition of 'average' but actually tells you exactly how it works: what does it take as input, what does it return, how is it implemented, what are it's limits. You can write the code that does the thing and explains itself easier than you could explain the same about a function named 'average'. I think this lecture is different/older and also APL can be quite a bit implementation dependent.

The one line Conway's Game of Life is just a bit of awesome. The Unicode is awesome, the plethora of operators is awesome, the sussinctness of being able to put that proposal of a universe into so few meaningful characters.... awesome.

In some sort of way it's why I prefer Perl over something like Python. There's a bit of Huffman encoding going on and at least allowing for the language to really fit the longer-time user without catering only to the beginner. Few programming languages can pull both off at the same time. If it's restricted to the simple and direct suitable for the beginner with little room for mutation then it's not good for the experienced as it becomes too verbose. If it's highly notational for the studied user then it becomes hard for the beginner. Learning curves and all that.

I'd personally like everybody to check out Raku (nee Perl 6) as a language that is intended to serve both sides of that equation. A decent presentation is 2016 - On The Shoulders Of Giants - Damian Conway (and one should never pass up the opportunity to watch a Damian Conway presentation). But you sorta have to watch for the point where he does Quicksort in LISP but (nope, actually Raku) and Haskell (but again nope, actually Raku). One of the reasons Raku took so long was that goal of being able to be as simple as BASIC or Logo while still being able to do APL like crazy.
posted by zengargoyle at 4:30 PM on October 11, 2020 [2 favorites]


J’s idea of treating scalars as arrays of one element is just bad. Treating one-element arrays special is bad. Privileging 1-dimensional arrays in this way is bad. I mean, a scalar could just as easily and wrongly been a 1 x 1 x 1 3-dimensional array. (However I’m not sure J even had those; I closed the tab at that point.)
posted by sjswitzer at 4:31 PM on October 11, 2020


Special operators and overloading are neither bad not bad in combination, but they can be misused.

In math, + can mean any number of things, depending on what is being “added,” but you would expect it to mean something that has an additive identity, associativity, etc. Category theory provides an exhaustive way of thinking about this.

Having a notation like + and a set of expectations about what it will mean over arbitrary domains is a decidedly good thing.

J is weird because its operators are gibberish concaténations of ASCII characters. But there’s really no reason at all to accept that limitation today.
posted by sjswitzer at 4:50 PM on October 11, 2020


Sjswitzer, if you use "++" to mean both "increment" as a monadic operator and string concatenation as a dyadic operator it's not the end of the world. You've just sacrificed a bit of clarity for convenience. But if you invent a special symbol (e.g., "⨁") that I can't type easily then you've made the code both unclear and a pain to input. Just, why would you do that?
posted by Joe in Australia at 5:21 PM on October 11, 2020


I always take that symbol for XOR and would find it more familiar than ^. Julia uses ⊻, which is also evidently standard but somehow I’d never seen it before.

IDEs can provide easy ways to enter those characters and some do.

Good notation and consistent conventions can be a real boon for expressing and communicating complex ideas. Julia does a good job of it, IMO, and J decidedly does not.
posted by sjswitzer at 5:33 PM on October 11, 2020


I’m sad that Julia didn’t restore = to it’s rightful place as equality rather than assignment. It’s a sad tradition that Fortran started and C perpetuated. Algol and Pascal got it that right at least. I can understand why they did it but still sad about it.
posted by sjswitzer at 5:39 PM on October 11, 2020 [3 favorites]


There are a number of books available by Iverson and others, with Iverson's aimed at teaching math using J. Calculus has been a nice companion to Thompson's Calculus Made Easy, it feels clear that Iverson was a teacher first and concepts are explained patiently, without overwhelming students with minutiae. Using J has the same sense of thoughtfulness; sure the syntax isn't like what people are used to, but the pieces fit together in such a way that you can really understand a problem. I've never written something in J and come away thinking "I don't know why it works, but it works", which I can't say for other languages.

While the J community is really small it has been among the best to participate in, in my experience. The mail archive goes back to the 90s, but new questions receive fast feedback that isn't just helpful but often contains historical trivia and interesting stories about why things work the way they do. Roger Hui (the major contributor in designing J with KEI) at some point joined Dyalog to develop a commercial APL, but he's still on the mailing list contributing answers and history. Also, Dyalog's APL has started picking up some of the better ideas from J.

I have a lot of fun with J but it is sure can be a bummer to bring up in conversation. Professional programmer types inevitably shit all over it having never tried it or bothered trying to understand it. The most prolific and engaged J users I know are not programmers but actuaries, scientists, mathematicians etc. This has the nice side-effect of limiting conversation about syntax and pointless "this is how I would write it in C/Lisp/Python/R" and instead centering on interesting problems.
posted by noop at 6:24 PM on October 11, 2020 [3 favorites]


This article is supposed to be in praise of clarity?

I suppose it’s telling that the form of notation missing from the list is the one it’s written in.
posted by snuffleupagus at 8:52 PM on October 11, 2020


J and APL are great. The reaction to it tends to be pretty dichotomous.

Most programmers spend a great deal of time linking frameworks together in efficient and robust ways and for those people APL is of no use at all. For people who use code to do math (a very small subset and mostly made up of people whose job title is not programmer or software engineer), APL and its derivatives make a lot more sense.

However I do agree that if you're already creating new symbols or digraphs then why on earth would you also overload them to have completely different meanings as unary operators? It's one thing when you're programming on a terminal with a limited character set but none of those restrictions matter any more.
posted by atrazine at 4:12 AM on October 12, 2020 [1 favorite]


The most prolific and engaged J users I know are not programmers but actuaries, scientists, mathematicians etc

Ding ding ding! It's nickname is even Actuarial Programming Language. My first job as an actuary (which was not too long ago in the programming world) we used APL and I actually got fairly good at it. The program we used for it was so old that when Windows upgraded to 10 (? I think? dont know exactly), we each kept an old laptop with Windows XP that would still run the program.

I had previously failed a Java programming class in college, and then changed my major to avoid having to take it again, so at first I was pretty terrified, but it went alot easier than Java for me at least and because of that I now have the confidence that I can learn programming languages!
posted by LizBoBiz at 1:02 AM on October 13, 2020 [2 favorites]


« Older You meant a full head of garlic, not a clove...   |   "Not to transmit an experience is to betray it.” –... Newer »


This thread has been archived and is closed to new comments