APL and J

Thursday 22 April 2004

For some reason, the topic of APL came up yesterday at the office. APL is one wild-ass idiosyncratic language. It stands for A Programming Language, and was created in 1962 by Ken Iverson. One of its most unusual aspects is that it requires an entirely new character set, including not only Greek letters, but new symbols created by Iverson. To add to the typographic diversity, even more new symbols were created by backspacing and overstriking two symbols together!

Here’s an example I scanned from an APL book:

Some typical APL

The lamp character introducing the comments is formed by overstriking a small circle with a mathematical intersection character. The difficulty of entering this symbol may help explain the typical lack of comments in APL programs!

Procedures are created with numbered lines of statements, and the only structuring mechanism is the goto (the right-pointing arrow):

A procedure written in APL

APL is really a calculator on mega-steroids. Its pervasive matrix operations give the programs their particular flavor. Looping is rare, with data in matrices acted on with single strokes. To use an analogy, where a more typical programming language lets you deal cards one at a time from a deck, with APL you usually figure out how to throw the entire deck into the air so that the cards all land where they should. For example, this hex dump program has no loops or gotos at all.

There are more modern implementations of APL that solve the character set problem. J seems to be just an implementation of APL without the wacky characters, although the home page doesn’t mention APL!

Comments

[gravatar]
Paul R 4:58 AM on 23 Apr 2004

several financial applications are still written in apl. there's a swaps derivatives program called 'devon' that comes to mind. i knew a support developer for it. he always said it was like coding in klingon.

[gravatar]
Adrian Howard 6:42 AM on 23 Apr 2004

Yeah. I know a couple of statistics fiends who still swear by APL.

Perl 6 is following in APLs footsteps by adopting several non-ASCII characters into the core language like and .

[gravatar]
Carl Tyler 12:39 PM on 23 Apr 2004

An APL keyboard will help you greatly if you ever have to use it. First time I saw one I wondered what was going on.

[gravatar]
Andy Neilson 9:21 AM on 24 Apr 2004

It has been quite a while since I've used it, I spent a fair bit of my life working in APL. For some kinds of applications it is an amazing tool. Given the right application, the highly parallel and multi-dimensional nature of the language can be extremely powerful.

One downside is that the extreme conciseness of the language can lead to extremely obscure code. It is possible to write clear code (where conciseness is an asset), but it takes some discipline. I've certainly been guilty of reducing an entire program down to a single impenetrable line of code.

I may be mangling the story, but I think APL started out as a mathematical notation to describe the IBM S/360 architecture. It was only later on that it was turned into an executable language. What a concept: a computer language with a mathematical basis!

APL is still around, and it continues to be used. I've since rewired my brain for other languages.

[gravatar]
Randy MacDonald 12:17 AM on 13 Sep 2005

APL is definitely an acquired taste. The statements people usually make are based mostly on myth. For example, the difficulties in entering the comment symbol were removed in the early 1980's with PC keyboards. Also the phrase "comments lie, code doesn't" makes one wonder what the fuss is about. And it's like coding in Elvish: a bit magical.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.