🎓 Chapter 7: Each & Rank Operators
When working with nested arrays (boxed elements) or multi-dimensional tensors, APL provides higher-order operators to control application depth.
---
1. Enclosure (⊂) & Nested Arrays
The Enclose function (⊂ Y) boxes an array Y into a single scalar cell. This allows creating heterogeneous lists containing vectors of different lengths!
⍝ Box three vectors of different lengths
Boxes ← (⊂1 2 3) (⊂4 5) (⊂6 7 8 9)
Boxes
---
2. The Each Operator (f¨)
If you apply a function f to a nested array directly, APL operates on the boxes themselves.
To apply f inside each individual box, attach the Each operator (¨)!
⍝ Count the length of each individual box using (⍴¨)
⍴¨ Boxes
---
3. The Rank Operator (f⍤R)
The Rank Operator (⍤) specifies the tensor rank depth at which function f should operate.
f⍤1 Mapplies functionfto each 1D row vector of matrixMindependently.
M ← 3 4 ⍴ ⍳ 12
⍝ Reverse each row of matrix M independently using (⌽⍤1)
⌽⍤1 M← Chapter 6: Dfns ({⍺ ⍵}), Guards & Recursion Chapter 8: Sorting (⍋ ⍒), Grouping (⌸) & Data Manipulation →