Mix: Difference between revisions

Jump to navigation Jump to search
45 bytes added ,  21:52, 10 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
(Put examples section first)
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 16: Line 16:
       ⍴↑x ⍝ ↑x is a non-nested 2-d array
       ⍴↑x ⍝ ↑x is a non-nested 2-d array
3 3
3 3
</source>
</syntaxhighlight>


Example application, to find the longest common prefix:
Example application, to find the longest common prefix:
Line 25: Line 25:
       lcp 'choco' 'choky' 'chom'
       lcp 'choco' 'choky' 'chom'
cho     
cho     
</source>
</syntaxhighlight>


== History ==
== History ==
Line 31: Line 31:
Early experiments in array nesting usually defined a primitive to extract the contents of a nested [[scalar]], but did not always specify how it should behave on an array. [[Jim Brown]]'s "A Generalization of APL",<ref>[[Jim Brown]]. [http://www.softwarepreservation.org/projects/apl/Books/AGENERALIZATIONOFAPL "A Generalization of APL"] (Ph.D. thesis). 1971.</ref> which would become [[APL2]], defined such a primitive, "reveal", while stating that it "may be undefined" on non-scalar arrays.
Early experiments in array nesting usually defined a primitive to extract the contents of a nested [[scalar]], but did not always specify how it should behave on an array. [[Jim Brown]]'s "A Generalization of APL",<ref>[[Jim Brown]]. [http://www.softwarepreservation.org/projects/apl/Books/AGENERALIZATIONOFAPL "A Generalization of APL"] (Ph.D. thesis). 1971.</ref> which would become [[APL2]], defined such a primitive, "reveal", while stating that it "may be undefined" on non-scalar arrays.


Mix (<source lang=apl inline>↑</source>) was first introduced by [[NARS]] in 1981.<ref>Carl M. Cheney. [http://www.sudleyplace.com/APL/Nested%20Arrays%20System.pdf ''APL*PLUS Nested Arrays System''] ([[NARS]] reference manual). [[STSC]]. 1981.</ref> It required all elements to have matching shape, and allowed a [[Function axis|specified axis]] to define where in the result array their axes would be placed. In the same year, [[SHARP APL]] introduced the concept of a [[box]]ed array, along with the function Disclose (<source lang=apl inline>></source>).<ref>[[Ken Iverson]]. SATN-41: [https://www.jsoftware.com/papers/satn41.htm Composition and Enclosure]. [[IPSA]]. 1981-06-20.</ref> In SHARP, Disclose was simply defined to be the inverse of Enclose, but given [[function rank]] 0 so that it would disclose each box in an argument and combine the results. Based on SHARP's definition of [[Rank (operator)|Rank]], the arrays to be combined were required to have the same [[shape]], and because of its [[flat array model]], they also had to have the same type (numeric, character, or boxed), as otherwise the result array would not be representable.
Mix (<source lang=apl inline>↑</syntaxhighlight>) was first introduced by [[NARS]] in 1981.<ref>Carl M. Cheney. [http://www.sudleyplace.com/APL/Nested%20Arrays%20System.pdf ''APL*PLUS Nested Arrays System''] ([[NARS]] reference manual). [[STSC]]. 1981.</ref> It required all elements to have matching shape, and allowed a [[Function axis|specified axis]] to define where in the result array their axes would be placed. In the same year, [[SHARP APL]] introduced the concept of a [[box]]ed array, along with the function Disclose (<source lang=apl inline>></syntaxhighlight>).<ref>[[Ken Iverson]]. SATN-41: [https://www.jsoftware.com/papers/satn41.htm Composition and Enclosure]. [[IPSA]]. 1981-06-20.</ref> In SHARP, Disclose was simply defined to be the inverse of Enclose, but given [[function rank]] 0 so that it would disclose each box in an argument and combine the results. Based on SHARP's definition of [[Rank (operator)|Rank]], the arrays to be combined were required to have the same [[shape]], and because of its [[flat array model]], they also had to have the same type (numeric, character, or boxed), as otherwise the result array would not be representable.


[[APL2]], released in 1984, used the same name Disclose as SHARP APL but introduced the glyph [[Right Shoe]] (<source lang=apl inline>⊃</source>). It shared NARS's [[function axis]] definition, but extended the function to allow argument elements with different [[shape]]s as long as they had the same [[rank]]. Arrays with different shapes would be padded using [[fill element]]s as with [[Take]] to bring them to a common shape large enough to contain every element.
[[APL2]], released in 1984, used the same name Disclose as SHARP APL but introduced the glyph [[Right Shoe]] (<source lang=apl inline>⊃</syntaxhighlight>). It shared NARS's [[function axis]] definition, but extended the function to allow argument elements with different [[shape]]s as long as they had the same [[rank]]. Arrays with different shapes would be padded using [[fill element]]s as with [[Take]] to bring them to a common shape large enough to contain every element.


A further extension was introduced as a consequence of [[J]]'s definition of the [[Rank operator]]. In J, result arrays in a function applied with rank can have different [[rank]]s, and results with lower rank are brought to a common rank by adding leading 1s to the shape. This change was taken up by [[Dyalog APL]] in [[Dyalog APL 14.0|version 14.0]], which introduced [[Rank (operator)|Rank]] following J's definition, in order to make Mix and Rank consistent. However, Dyalog differs from J in that it permits [[mixed array]]s, so while in J an array containing a mix of numbers, characters, and boxes cannot be mixed, in Dyalog any array at all can be mixed.
A further extension was introduced as a consequence of [[J]]'s definition of the [[Rank operator]]. In J, result arrays in a function applied with rank can have different [[rank]]s, and results with lower rank are brought to a common rank by adding leading 1s to the shape. This change was taken up by [[Dyalog APL]] in [[Dyalog APL 14.0|version 14.0]], which introduced [[Rank (operator)|Rank]] following J's definition, in order to make Mix and Rank consistent. However, Dyalog differs from J in that it permits [[mixed array]]s, so while in J an array containing a mix of numbers, characters, and boxes cannot be mixed, in Dyalog any array at all can be mixed.

Navigation menu