≡) is a monadic primitive function that returns an array's depth. In the APL array model, the depth of an array is the number of levels of nesting or boxing it exhibits. In some languages, Depth returns a negative result to indicate that not all paths through the array have the same depth.
Nested array depth
Nested APLs vary in their definition of depth. They may take into account the array's prototype, or not, and may use the positive or signed depth as defined below (the choice may also depend on migration level). The APL Wiki generally uses "depth" to mean the positive depth.
The positive depth of an empty array is usually defined (for example, in Dyalog APL) to be the depth of its prototype plus one. It can also be set to 1, since it contains no elements but is not a simple scalar. This is the case in ngn/apl and dzaima/APL.
An array has a consistent depth if it is a simple scalar, or if all of its elements (including the prototype, if prototypes are used to determine depth) have a consistent depth and are equal in depth. For example, the following works in all nested APLs with stranding:
≡('ab' 'cde')('fg' 'hi') 3
The signed depth of an array is an integer with absolute value equal to its positive depth. It is negative if and only if the array does not have a consistent depth.
A simple array must have a consistent depth, because it is either a simple scalar or contains only simple scalars. In the latter case each element necessarily has depth 0 and a consistent depth. Because of this it is not possible to have an array with a signed depth of ¯1: any array with a positive depth of 1 must be simple, and hence have consistent depth.
Flat array depth
In the flat array model, the depth is the number of levels of boxing in an array. More precisely, the depth of a non-boxed or empty array is 0, and a non-empty boxed array has depth equal to one plus the maximum of the depths of the arrays it contains.
The J language uses the token
L. and name "Level Of" for depth.
|APL features |
|Built-ins||Primitive function ∙ Primitive operator ∙ Quad name|
|Array model||Shape ∙ Rank ∙ Depth ∙ Bound ∙ Index ∙ Axis ∙ Ravel ∙ Ravel order ∙ Element ∙ Scalar ∙ Vector ∙ Matrix ∙ Simple scalar ∙ Simple array ∙ Nested array ∙ Box ∙ Cell ∙ Major cell ∙ Subarray ∙ Empty array ∙ Prototype|
|Concepts and paradigms||Leading axis theory ∙ Scalar extension ∙ Conformability ∙ Scalar function ∙ Pervasion ∙ Glyph ∙ Identity element ∙ Total array ordering|
|Errors||LIMIT ERROR ∙ RANK ERROR ∙ SYNTAX ERROR|
|APL built-ins |
|Monadic||Conjugate ∙ Negate ∙ Signum ∙ Not ∙ Roll ∙ Type|
|Dyadic||Add ∙ Subtract ∙ Equal to (Xnor) ∙ Not Equal to (Xor) ∙ Minimum ∙ Maximum ∙ Comparison functions|
|Structural||Shape ∙ Reshape ∙ Tally ∙ Depth ∙ Ravel ∙ Reverse ∙ Raze ∙ Mix ∙ Cut (K) ∙ Pair ∙ Replicate ∙ Partitioned Enclose|
|Selection||Take ∙ Drop ∙ Unique ∙ Identity ∙ Select|
|Selector||Index generator ∙ Interval Index ∙ Indices|
|Computational||Match ∙ Not Match ∙ Nub Sieve ∙ Format ∙ Execute|
|Primitive operators||Monadic||Each ∙ Replicate|
|Arrays||Index origin ∙ Migration level|
|Other||Zilde ∙ High minus ∙ Function axis|