APL and J

APL is that language that everyone thinks they ought to learn someday. No one actually knows the language, and no one has the slightest intention of ever actually learning it the language, but everyone thinks they ought to.

APL is a language designed by a mad-man. It provides dozens of array-oriented functions that would be useful in a more conventional language, but these functions are designated using bizarre, meaningless symbols instead of mnemonics. There are over 100 special APL symbols that exist only in fonts designed especially for APL. Each symbol represents both a two-operand function and a one-operand function. These functions are invoked by using the symbol as a prefix operator or as an infix operator. Sometimes the two functions are related, sometimes they're not. Extensions to the language (i.e. new function definitions) must give two definitions (one of which can be null) one for the infix version of the function, one for the prefix version. Some functions actually have three operands, one of which is concatenated to the operator symbol, although you're supposed to pretend not to notice this.

In addition to inventing a new programming language, the inventors of APL and its derivatives have also invented their own human language(s) to describe their programming language(s). The result is that the documentation is largely gibberish. Here is an example from the documentation for the J language, an APL derivative:

"If m is not a gerund, x m} y is formed by replacing by x those parts of y selected by m&{ (an error is signalled if such selection requires fill)."

J is an APL derivative which is essentially the same as APL with all the funny symbols replaced by ASCII character sequences. The designers of J have been true to the original APL model, and have been careful to make their symbol sequences as meaningless as possible. Here are some of the sequences, one per line:


The net result of this is that J is just as utterly incomprehensible as APL.

On the other hand, the functions provided by APL/J really are useful! In any other language, they would be viewed as a gift from heaven. If the language had been designed in a way that made it easy to use it probably would have been one of the most wildly successful languages in history. As it is, it is struggling to survive.

The following program implements the same sieve algorithm as the other programs in this series, with the exception that the "is prime" string is omitted from the lines of output. (I just couldn't stand working with this language any more, so I stopped once I got the primes to print out.) Please note that writing all this code is not in the true spirit of APL. APL provides a function to enumerate primes, so the same output can be obtained with the following one-line program.

p: i. 168 1

This program compiles and runs on the J601 interpreter.

f=: 3 : 0

a =: 1 (i. y)} i. y

a =: 0 (0 1)} a

b =: 0

while. b < #(I. a)


c =: b} (I. a)

d =: <. ((y-1) % c)

d =: d - 1

e =: i. d

e =: e + 2

e =: e * c

a =: 0 e} a

b =: b + 1


a =: I. a

b =: #a

b =: b , 1

b $ a


f 1000

Click Here for the actual code.