trusted
41
edits
m (1 revision imported) |
(update dzaima/APL) |
||
Line 3: | Line 3: | ||
== Nested array 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 | 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. | ||
In the [[nested array model]], the depth is defined using the base case of a [[simple scalar]], which by definition has depth 0. | In the [[nested array model]], the depth is defined using the base case of a [[simple scalar]], which by definition has depth 0. | ||
Line 9: | Line 9: | ||
The positive depth of a non-[[empty]] array other than a simple scalar is defined to be the largest depth among its [[element]]s, plus one. Thus a [[simple]] but non-[[scalar]] array has depth 1. | The positive depth of a non-[[empty]] array other than a simple scalar is defined to be the largest depth among its [[element]]s, plus one. Thus a [[simple]] but non-[[scalar]] array has depth 1. | ||
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]]. | 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 | 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]]: | ||
For | |||
<source lang=apl> | <source lang=apl> | ||
≡('ab' 'cde')('fg' 'hi') | ≡('ab' 'cde')('fg' 'hi') | ||
3 | 3 | ||
</source> | </source> | ||
The signed depth of an array is an integer with [[Magnitude|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. | 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. |