Array model: Difference between revisions

Jump to navigation Jump to search
m
→‎Based array theory: Link to WP instead of APL Wiki for NumPy and Julia
(→‎Nested array theory: quote by Scholes)
m (→‎Based array theory: Link to WP instead of APL Wiki for NumPy and Julia)
 
(2 intermediate revisions by one other user not shown)
Line 58: Line 58:
== Based array theory ==
== Based array theory ==


Based array theory discards the principle that all data should be stored in arrays, instead defining basic types such as characters and numbers independently of arrays and arrays as a collection type—possibly one of many—that can contain any data. This model does not have any widely accepted name, with the term "based system" introduced in an [[APL Quote Quad]] paper in 1981.<ref>Randall Mercer. [https://dl.acm.org/doi/abs/10.1145/586656.586663 "A based system for general arrays"]. [[APL Quote Quad]] Volume 12, Issue 2. 1981-12.</ref> However, as it is the natural model when arrays are added to an existing programming system, it is common in array libraries such as [[NumPy]], [[wikipedia:ILNumerics|ILNumerics]], and [[wikipedia:Haskell (programming language)|Haskell]]'s [https://hackage.haskell.org/package/repa Repa], as well as the language [[Julia]]. It has also been promoted with the mnemonic "APL+1" by Jacob Brickman<ref>Jacob Brickman. "Behavior of APL primitives in a system with depth-1 scalars (APL+1)". [[APL-Germany]] ''APL-Journal'' 2019 1-2 ([https://apl-germany.de/wp-content/uploads/2020/06/APL_Journal_2019_12.pdf#page=5 pdf]).</ref>, and is used by the APL-family language [[BQN]].
Based array theory discards the principle that all data should be stored in arrays, instead defining basic types such as characters and numbers independently of arrays and arrays as a collection type—possibly one of many—that can contain any data. This model does not have any widely accepted name, with the term "based system" introduced in an [[APL Quote Quad]] paper in 1981.<ref>Randall Mercer. [https://dl.acm.org/doi/abs/10.1145/586656.586663 "A based system for general arrays"]. [[APL Quote Quad]] Volume 12, Issue 2. 1981-12.</ref> However, as it is the natural model when arrays are added to an existing programming system, it is common in array libraries such as [[wikipedia:NumPy|NumPy]], [[wikipedia:ILNumerics|ILNumerics]], and [[wikipedia:Haskell (programming language)|Haskell]]'s [https://hackage.haskell.org/package/repa Repa], as well as the language [[wikipedia:Julia (programming language)|Julia]]. It has also been promoted with the mnemonic "APL+1" by Jacob Brickman<ref>Jacob Brickman. "Behavior of APL primitives in a system with depth-1 scalars (APL+1)". [[APL-Germany]] ''APL-Journal'' 2019 1-2 ([https://apl-germany.de/wp-content/uploads/2020/06/APL_Journal_2019_12.pdf#page=5 pdf]).</ref>, and is used by the APL-family language [[BQN]].


=== Mutable based arrays ===
=== Mutable based arrays ===
Line 95: Line 95:
In nested APLs, a simple non-scalar array has depth 1, an array containing only depth 1 arrays has depth 2, and a simple scalar (e.g a number or character) has depth 0.
In nested APLs, a simple non-scalar array has depth 1, an array containing only depth 1 arrays has depth 2, and a simple scalar (e.g a number or character) has depth 0.


Most APLs provide a Depth function <source lang=apl inline>≡</source> to find an array's depth. For example:
Most APLs provide a Depth function <syntaxhighlight lang=apl inline>≡</syntaxhighlight> to find an array's depth. For example:
<source lang=apl>
<syntaxhighlight lang=apl>
       ≡('ab' 'cde')('fg' 'hi')
       ≡('ab' 'cde')('fg' 'hi')
3
3
</source>
</syntaxhighlight>


APLs vary in their definition of depth: for example some may return the depth with a sign to indicate that some level of the array mixes elements of different depths.
APLs vary in their definition of depth: for example some may return the depth with a sign to indicate that some level of the array mixes elements of different depths.

Navigation menu