Pair

From APL Wiki
(Redirected from Juxtapose)
Jump to navigation Jump to search

Pair () or Juxtapose is a primitive ambivalent function that constructs a vector of its arguments, present in Extended Dyalog APL, dzaima/APL, and BQN (as ). 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 , (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 {⍺←,⊂ ⋄ ⍺ ⍵}, 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.

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

History

By 1982, Nial had defined four infix functions to join two arrays, enclosing any combination of them.[2] link encloses neither argument, giving Catenate, while pair encloses both, giving dyadic Pair. hitch encloses only the left to give Link, and append encloses the right.

In APL, Link precedes Pair significantly, as it was defined in SHARP APL in 1983,[3] 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 , as enlist, but dyadic , as catenate. Ambivalent Pair appears in I as ; 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 in Extended Dyalog APL in 2018, and then adopted into dzaima/APL. It was added to BQN with the glyph in 2021.

Documentation

References

  1. "Composition and Enclosure" § Composition Operators. SATN-41, 1981-06-20.
  2. Fl. Schmidt and M. A. Jenkins. Array diagrams and the Nial approach at APL82.
  3. "Language Extensions of May 1983". SATN-45, 1983-05-02.
APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
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 axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector