APL Rank Operator (⍤): Applying Functions to Specific Array Cells
The APL rank operator (⍤) lets you apply functions to specific array cells by rank—rows, columns, or higher‑dimensional slices—without writing explicit loops.
20 Sept 2026, 16:39 UTC

The Useful Answer: What the Rank Operator Does
The rank operator ⍤ tells APL to apply a function to sub‑arrays of a specific rank instead of to the whole array. A rank‑k cell is a slice whose shape consists of the last k dimensions of the argument; the leading dimensions form the frame of cells. By choosing the rank you get row‑wise, column‑wise, or higher‑dimensional operations without explicit loops.
How ⍤ Works
For a monadic function f, f⍤k maps f over each rank‑k cell. For a dyadic function f, f⍤(l r) pairs rank‑l cells of the left argument with rank‑r cells of the right argument; the frames must be compatible (broadcastable). Negative ranks are complementary: ¯k selects rank (r‑k) where r is the argument’s rank.
Worked Example: Row‑wise Sum of a Matrix
M ← 3 4 ⍴ ⍳12 ⍝ 3 rows, 4 columns
M
1 2 3 4
5 6 7 8
9 10 11 12
(+/⍤1) M
10 26 42
+/ sums each rank‑1 cell (each row). The result is a vector whose length equals the number of rows (the frame). The equivalent each‑operator (+/¨)M works but incurs more interpreter overhead.
Limits and Common Mistakes
Rank versus Depth
Rank is the number of dimensions (⍴⍴X), not nesting level. The rank operator does not descend into nested arrays; use ¨ (each) or ⍣ (power) for that.
NESTED ← (1 2 3) (4 5 6) ⍝ vector of vectors, rank 1
+/⍤1 NESTED ⍝ RANK ERROR – cells are scalars
+/¨ NESTED ⍝ correct: 6 15
Invalid Rank Operands
The right operand must be an integer scalar (monadic) or a two‑element integer vector (dyadic). Non‑integers raise DOMAIN ERROR; ranks larger than the argument’s rank raise RANK ERROR at runtime.
+/⍤1.5 M ⍝ DOMAIN ERROR
+/⍤3 M ⍝ RANK ERROR (M is rank 2)
Ragged Arrays
APL arrays are rectangular; ⍤ cannot express irregular cell shapes. For jagged data use nested arrays with ¨ or switch to a language that supports ragged tensors.
Interpreter Support
The rank operator is part of ISO/IEC 13751:2001 and present in Dyalog APL, GNU APL, NARS2000, and dzaima/APL. Older systems (APL2, IBM APL) lack ⍤; they rely on ⎕EA or explicit loops. Verify target support before using ⍤ in portable code.
Binding Precedence in dfns
In a dfn, ⍤ binds tightly: f⍤k g Y parses as (f⍤k) g Y. Parenthesise when combining with other operators, e.g. (f⍤k)⍣n.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.