APL
APL (A Programming Language) grew from a mathematical notation invented by Kenneth Iverson at Harvard in the late 1950s, and became a programming language at IBM in the 1960s. It was awarded the Turing Award for Iverson in 1979. Every value is an array, every function works on whole arrays, and each operation has a single-symbol name.
Paradigm: Array-Oriented Programming
What Makes APL Special
- Arrays are the only data. A scalar is a 0-dimensional array and a matrix has rank 2. Functions apply to arrays of any shape without loops.
- One glyph per operation.
+adds,⍳counts,⍴reshapes and∘.|builds a table. The keyboard has special symbols, and ideas are typed in very few characters. - Right-to-left evaluation. There is no operator precedence.
2×3+4means 2 × (3 + 4), and you read a line from right to left. - Operators build functions. Operators such as
/(reduce) and∘.(outer product) take functions and return new ones.+/means "sum". - Tacit programming. Functions can be combined without naming arguments:
avg←+/÷≢is the whole definition of the average.
Example: Average and primes in one line each
avg ← +/÷≢
avg 2 4 4 4 5
3.8
primes ← {(2=+⌿0=(⍳⍵)∘.|⍳⍵)/⍳⍵}
primes 30
2 3 5 7 11 13 17 19 23 29
How It Works
+/÷≢is a train: sum (+/) divided by (÷) the count (≢). Applied to2 4 4 4 5it gives 19 ÷ 5 = 3.8.- In
primes,⍳⍵gives 1 to n and∘.|builds a table of remainders of every number divided by every other. 0=marks the zeros (exact divisors), and+⌿counts them per column. A prime has exactly two divisors, so2=selects primes./then filters⍳⍵with that mask. The method is brute force, but it is the whole program with no loop, and it shows how array thinking works.
History and Where It Is Used
APL and its descendants are used in finance (Dyalog APL and kdb+/q at banks and trading firms), insurance, actuarial work and analytics, where their brevity lets analysts explore data very quickly. Dyalog APL is free for personal use, and the ideas live on in NumPy, R, MATLAB and Julia.
Learn More
- Learn APL (free)
- APL Wiki
- Back to Array-Oriented Programming or the PGP roadmap.