Pair: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(Remove Over workaround: Over's now supported in many APLs)
(More explicit description of the monadic case)
Line 1: Line 1:
{{Built-in|Pair|⍮}} or '''Juxtapose''' is a [[primitive function]] equivalent to the [[dfn]] <syntaxhighlight lang=apl inline>{⍺←,⊂ ⋄ ⍺ ⍵}</syntaxhighlight> which aids in constructing nested arrays during [[tacit programming]] where [[stranding]] by juxtaposition is not available. It is also equivalent to 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"] §
{{Built-in|Pair|⍮}} or '''Juxtapose''' is a [[primitive]] [[ambivalent function]] that constructs a [[vector]] of its [[argument]]s. It 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. It was introduced in [[Extended Dyalog APL]] in 2018, and then adopted into [[dzaima/APL]]. It was added to [[BQN]] with the glyph <code>⋈</code> in 2021. The [[monadic]] case, which is similar to [[Enclose]] except that it gives a result of [[rank]] 1 rather than 0, is called '''Enlist''' in BQN, as well as [[K]], where it is the monadic case of <code>,</code> (K has no dyadic Pair primitive).
Composition Operators. SATN-41, 1981-06-20.</ref>. It was introduced in [[Extended Dyalog APL]], and then adopted into [[dzaima/APL]]. It was added to [[BQN]] with the glyph <code>⋈</code> in 2021.


== Common usage ==
== Common usage ==

Revision as of 15:44, 6 March 2024

Pair () or Juxtapose is a primitive ambivalent function that constructs a vector of its arguments. It can be implemented as the dfn {⍺←,⊂ ⋄ ⍺ ⍵}, or the catenation of the enclosed arguments, written ,⍥⊂ using Over.[1] Pair aids in constructing nested arrays in tacit programming, where stranding by juxtaposition is not available. It was introduced in Extended Dyalog APL in 2018, and then adopted into dzaima/APL. It was added to BQN with the glyph in 2021. The monadic case, which is similar to Enclose except that it gives a result of rank 1 rather than 0, is called Enlist in BQN, as well as K, where it is the monadic case of , (K has no dyadic Pair primitive).

Common usage

Its plain usage is in pairing up two parallel values:

Try it online!

      6 7 8(+⍮-)3
┌───────┬─────┐
│9 10 11│3 4 5│
└───────┴─────┘

It can also be combined with Mix to increase rank rather than depth:

Try it online!

      6 7 8(+↑⍤⍮-)3
9 10 11
3  4  5

External links

Documentation

See also

References

  1. "Composition and Enclosure" § Composition Operators. SATN-41, 1981-06-20.
APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)
Quad names Index originComparison toleranceMigration levelAtomic vector