Pair: Difference between revisions

Jump to navigation Jump to search
2,263 bytes added ,  6 March
m (Text replacement - "{{APL built-ins}}" to "{{APL built-ins}}Category:Primitive functions")
(→‎History: Nial)
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Built-in|Pair|⍮}} is a [[primitive function]] equivalent to the [[dfn]] <source lang=apl inline>{⍺←,⊂ ⋄ ⍺ ⍵}</source> which aids in constructing nested arrays during [[tacit programming]] where [[stranding]] by juxtaposition is not available. It is also equivalent to <source lang=apl inline>,⍥⊂</source> using the [[Over operator]] or <source lang=apl inline>,⍨∘⊂⍨∘⊂</source> using only traditional operators. It was introduced in [[Extended Dyalog APL]], and then adopted into [[dzaima/APL]].
{{Built-in|Pair|⍮}} or '''Juxtapose''' is a [[primitive]] [[ambivalent function]] that constructs a [[vector]] of its [[argument]]s, present in [[Extended Dyalog APL]], [[dzaima/APL]], and [[BQN]] (as <code>⋈</code>). The [[monadic]] case is referred to as '''Half Pair''' in Extended Dyalog APL, and is similar to [[Enclose]] except that it gives a result of [[rank]] 1 rather than 0. This case is called '''Enlist''' in BQN, as well as [[K]], where it is the monadic case of <code>,</code> (K has no dyadic Pair primitive). Dyadic Pair is similar to the [[Link]] primitive in [[SHARP APL]] and [[J]], but Link has an asymmetric definition that adds its left argument to a vector right argument rather than creating a new vector.
 
Pair can be implemented as the [[dfn]] <syntaxhighlight lang=apl inline>{⍺←,⊂ ⋄ ⍺ ⍵}</syntaxhighlight>, or the [[catenate|catenation]] of the [[enclose]]d arguments, written <syntaxhighlight lang=apl inline>,⍥⊂</syntaxhighlight> using [[Over]].<ref>[https://www.jsoftware.com/papers/satn41.htm "Composition and Enclosure"] § Composition Operators. SATN-41, 1981-06-20.</ref> Pair aids in constructing nested arrays in [[tacit programming]], where [[stranding]] by juxtaposition is not available.


== Common usage ==
== Common usage ==
Line 5: Line 7:


[https://tio.run/##SyzI0U2pSszMTfz//1Hf1EdtE8wUzBUsNLQf9a7T1TT@/x8A Try it online!]
[https://tio.run/##SyzI0U2pSszMTfz//1Hf1EdtE8wUzBUsNLQf9a7T1TT@/x8A Try it online!]
<source lang=apl>
<syntaxhighlight lang=apl>
       6 7 8(+⍮-)3
       6 7 8(+⍮-)3
┌───────┬─────┐
┌───────┬─────┐
│9 10 11│3 4 5│
│9 10 11│3 4 5│
└───────┴─────┘
└───────┴─────┘
</source>
</syntaxhighlight>
{{Works in|[[dzaima/APL]], [[Extended Dyalog APL]]}}
{{Works in|[[dzaima/APL]], [[Extended Dyalog APL]]}}


Line 16: Line 18:


[https://tio.run/##SyzI0U2pSszMTfz//1Hf1EdtE8wUzBUsNLQftU181LvkUe86XU3j//8B Try it online!]
[https://tio.run/##SyzI0U2pSszMTfz//1Hf1EdtE8wUzBUsNLQftU181LvkUe86XU3j//8B Try it online!]
<source lang=apl>
<syntaxhighlight lang=apl>
       6 7 8(+↑⍤⍮-)3
       6 7 8(+↑⍤⍮-)3
9 10 11
9 10 11
3  4  5
3  4  5
</source>
</syntaxhighlight>
{{Works in|[[dzaima/APL]], [[Extended Dyalog APL]]}}
{{Works in|[[dzaima/APL]], [[Extended Dyalog APL]]}}


== History ==
By 1982, [[Nial]] had defined four infix functions to join two arrays, enclosing any combination of them.<ref>Fl. Schmidt and M. A. Jenkins. [https://doi.org/10.1145/800071.802258 Array diagrams and the Nial approach] at [[APL82]].</ref> <code>link</code> encloses neither argument, giving [[Catenate]], while <code>pair</code> encloses both, giving dyadic Pair. <code>hitch</code> encloses only the left to give [[Link]], and <code>append</code> encloses the right.
In APL, [[Link]] precedes Pair significantly, as it was defined in [[SHARP APL]] in 1983,<ref>[https://www.jsoftware.com/papers/satn45.htm "Language Extensions of May 1983"]. SATN-45, 1983-05-02.</ref> and included in the initial version of [[J]] in 1990.
In array languages based on the [[list model]], Pair also covers the functionality of [[Promote]] and [[Laminate]]. [[K]], released in the 1990s, defines monadic <code>,</code> as enlist, but dyadic <code>,</code> as [[catenate]]. Ambivalent Pair appears in [[I]] as <code>;</code> since 2012; no name is given in the documentation, but the implementation uses "itemize" (the same name as [[J]]'s Promote) and "cross".
Pair was defined as <syntaxhighlight lang=apl inline>⍮</syntaxhighlight> in [[Extended Dyalog APL]] in 2018, and then adopted into [[dzaima/APL]]. It was added to [[BQN]] with the glyph <code>⋈</code> in 2021.
== Documentation ==
* [https://mlochbaum.github.io/BQN/doc/pair.html BQN] (as <code>⋈</code>)
== References ==
<references />
{{APL built-ins}}[[Category:Primitive functions]]
{{APL built-ins}}[[Category:Primitive functions]]

Navigation menu