APL is an array-oriented programming language. This implementation supports
a subset of APL with Unicode glyphs and ASCII aliases. Expressions are
evaluated right-to-left: 2×3+4 is 2×(3+4) = 14.
All numeric values are 64-bit floating point (f64). Arrays are
stored as contiguous vectors with a shape. A scalar has shape [],
a vector has shape [n], a matrix has shape [r,c].
Negative number literals use high minus: ¯3 or _3 in ASCII.
Integer-valued floats display without decimals.
2×3+4 → 141 2 3(2×3)+4 → 10ι3 → 1 2 3x←5 or x gets 5⎕←42 or print 42⎕ or input — reads one line, parses as number(s)◊ or newline&x235D; to end of line, or NB to end of lineScalar functions apply element-wise to arrays and support scalar extension.
| Glyph | ASCII | Monadic | Dyadic | Example |
|---|---|---|---|---|
+ | Identity (conjugate) | Add | 2+3 → 5 | |
- | Negate | Subtract | -3 → ¯3 | |
× | mul | Signum (¯1, 0, 1) | Multiply | 3×4 → 12 |
÷ | div | Reciprocal | Divide | 10÷4 → 2.5 |
* | Exponential (ex) | Power | 2*10 → 1024 | |
| | Absolute value | Residue (modulo) | 3|7 → 1 | |
⌈ | ceil | Ceiling | Maximum | ⌈3.2 → 4 |
⌊ | floor | Floor | Minimum | ⌊3.7 → 3 |
= | — | Equal | 3=3 → 1 | |
≠ | ne | — | Not equal | 3≠4 → 1 |
< | — | Less than | 2<3 → 1 | |
> | — | Greater than | 3>1 2 3 → 1 1 0 | |
≤ | le | — | Less or equal | 3≤3 → 1 |
≥ | ge | — | Greater or equal | 3≥4 → 0 |
∧ | land | — | Logical AND | 1∧0 → 0 |
∨ | lor | — | Logical OR | 0∨1 → 1 |
~ | Not (logical) | Without | ~0 → 1 |
| Glyph | ASCII | Monadic | Dyadic | Example |
|---|---|---|---|---|
ι | iota | Index generator (1..N) | Index of | ι5 → 1 2 3 4 5 |
ρ | rho | Shape | Reshape | 2 3ρι6 → 2×3 matrix |
⌽ | rev | Reverse | Rotate | ⌽1 2 3 → 3 2 1 |
, | Ravel (flatten) | Catenate | 1 2,3 4 → 1 2 3 4 | |
↑ | take | — | Take | 3↑ι5 → 1 2 3 |
↓ | drop | — | Drop | 2↓ι5 → 3 4 5 |
≢ | tally | Tally (first axis length) | — | ≢1 2 3 4 → 4 |
Operators modify functions to produce new derived functions.
| Syntax | Name | Description | Example |
|---|---|---|---|
f/ | Reduce | Fold function across array (right to left) | +/1 2 3 4 → 10 |
f\ | Scan | Running reduction (prefix sums, etc.) | +\1 2 3 4 → 1 3 6 10 |
f¨ or f each | Each | Apply monadic function to each element | -¨1 2 3 → ¯1 ¯2 ¯3 |
∘.f | Outer Product | Apply dyadic function to all pairs | 1 2 3∘.×1 2 3 → multiplication table |
| Syntax | ASCII | Description |
|---|---|---|
¯ | _ | High minus (negative literal): ¯3 or _3 |
name←expr | name gets expr | Variable assignment |
⎕←expr | print expr | Print result |
⎕ | input | Read next line of input as number(s). Single number → scalar; space-separated numbers → vector; non-numeric → character codes. |
◊ | (newline) | Statement separator |
&x235D; | NB | Comment (to end of line) |
+/ι100
Result: 5050
1 2 3 4 5∘.×1 2 3 4 5
x←5 ◊ x+3
Result: 8
+/⎕
With input 1 2 3 4 5, result: 15
⎕ + ⎕
With input 10\n20 (two lines), result: 30
n gets 30 nums gets 1 drop iota n sieve gets (0=nums∘.|nums) +/ each nums gets (sieve=1) / nums
+/ 2 3ρ1 2 3 4 5 6
Result: 6 15 (row sums)
f64 (64-bit float)