Link: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - "<source" to "<syntaxhighlight")
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Built-in|Link|⊃}}, or <source lang=j inline>;</source> in [[J]], is a [[dyadic]] [[primitive function]] which builds a [[nested]] [[vector]] out of the two [[argument|arguments]]. Link is useful for building a nested array when [[stranding]] by juxtaposition is not available. Link first appeared as an extension to [[SHARP APL]]<ref>[https://www.jsoftware.com/papers/satn45.htm "Language Extensions of May 1983"]. SATN-45, 1983-05-02.</ref>.
{{Built-in|Link|⊃}}, or <syntaxhighlight lang=j inline>;</syntaxhighlight> in [[J]], is a [[dyadic]] [[primitive function]] which builds a [[nested]] [[vector]] out of the two [[argument|arguments]]. Link is useful for building a nested array when [[stranding]] by juxtaposition is not available. Link first appeared as an extension to [[SHARP APL]]<ref>[https://www.jsoftware.com/papers/satn45.htm "Language Extensions of May 1983"]. SATN-45, 1983-05-02.</ref>.


== Examples ==
== Examples ==


Link implements <source lang=apl inline>{(⊂⍺),⊆⍵}</source>, that is, the [[catenate|concatenation]] of [[enclose]] of the left argument and [[nest]] (enclose if simple) of the right argument. This allows to chain the function over multiple arrays to form a nested array. Note that both [[SHARP APL]] and [[J]] use [[flat array model]], so they allow boxing of a [[simple scalar]].
Link implements <syntaxhighlight lang=apl inline>{(⊂⍺),⊆⍵}</syntaxhighlight> or <syntaxhighlight lang=apl inline>,⍨∘⊂⍨∘⊆</syntaxhighlight>, that is, the [[catenate|concatenation]] of [[enclose]] of the left argument and [[nest]] (enclose if simple) of the right argument. This allows to chain the function over multiple arrays to form a nested array. Note that both [[SHARP APL]] and [[J]] use [[flat array model]], so they allow boxing of a [[simple scalar]].


<source lang=apl>
<syntaxhighlight lang=apl>
       1 2⊃3 4⊃5 6
       1 2⊃3 4⊃5 6
┌───┬───┬───┐
┌───┬───┬───┐
Line 14: Line 14:
│1│2│3│
│1│2│3│
└─┴─┴─┘
└─┴─┴─┘
</source>{{Works in|[[SHARP APL]]}}
</syntaxhighlight>{{Works in|[[SHARP APL]]}}


Because of the function's asymmetric nature, oddities may appear if the arrays are chained in a wrong order:
Because of the function's asymmetric nature, oddities may appear if the arrays are chained in a wrong order:


<source lang=apl>
<syntaxhighlight lang=apl>
       (1 2⊃3 4)⊃5 6
       (1 2⊃3 4)⊃5 6
┌─────────┬───┐
┌─────────┬───┐
Line 25: Line 25:
│└───┴───┘│  │
│└───┴───┘│  │
└─────────┴───┘
└─────────┴───┘
</source>{{Works in|[[SHARP APL]]}}
</syntaxhighlight>{{Works in|[[SHARP APL]]}}


Similarly, the chaining fails if the rightmost array is already nested:
Similarly, the chaining fails if the rightmost array is already nested:


<source lang=apl>
<syntaxhighlight lang=apl>
       1 2⊃3 4⊃<5 6
       1 2⊃3 4⊃<5 6
┌───┬───┬───┐
┌───┬───┬───┐
│1 2│3 4│5 6│
│1 2│3 4│5 6│
└───┴───┴───┘
└───┴───┴───┘
</source>{{Works in|[[SHARP APL]]}}
</syntaxhighlight>{{Works in|[[SHARP APL]]}}
What we really wanted was:
What we really wanted was:
<source lang=apl>
<syntaxhighlight lang=apl>
      1 2⊃3 4⊃<<5 6
┌───┬───┬─────┐
┌───┬───┬─────┐
│1 2│3 4│┌───┐│
│1 2│3 4│┌───┐│
Line 42: Line 43:
│  │  │└───┘│
│  │  │└───┘│
└───┴───┴─────┘
└───┴───┴─────┘
</source>
</syntaxhighlight>{{Works in|[[SHARP APL]]}}


Link is different from [[Pair]] <source lang=apl inline>⍮</source>, as Pair simply encloses both arguments and always produces a length-2 vector, so it cannot be used to construct a long nested array of uniform depth like Link does.
Link is different from [[Pair]] <syntaxhighlight lang=apl inline>⍮</syntaxhighlight>, as Pair simply encloses both arguments and always produces a length-2 vector, so it cannot be used to construct a long nested array of uniform depth like Link does.


== External links ==
== External links ==

Latest revision as of 21:02, 10 September 2022

Link (), or ; in J, is a dyadic primitive function which builds a nested vector out of the two arguments. Link is useful for building a nested array when stranding by juxtaposition is not available. Link first appeared as an extension to SHARP APL[1].

Examples

Link implements {(⊂⍺),⊆⍵} or ,⍨∘⊂⍨∘⊆, that is, the concatenation of enclose of the left argument and nest (enclose if simple) of the right argument. This allows to chain the function over multiple arrays to form a nested array. Note that both SHARP APL and J use flat array model, so they allow boxing of a simple scalar.

      1 2⊃3 4⊃5 6
┌───┬───┬───┐
│1 2│3 4│5 6│
└───┴───┴───┘
      1⊃2⊃3
┌─┬─┬─┐
│1│2│3│
└─┴─┴─┘
Works in: SHARP APL

Because of the function's asymmetric nature, oddities may appear if the arrays are chained in a wrong order:

      (1 2⊃3 4)⊃5 6
┌─────────┬───┐
│┌───┬───┐│5 6│
││1 2│3 4││   │
│└───┴───┘│   │
└─────────┴───┘
Works in: SHARP APL

Similarly, the chaining fails if the rightmost array is already nested:

      1 2⊃3 4⊃<5 6
┌───┬───┬───┐
│1 2│3 4│5 6│
└───┴───┴───┘
Works in: SHARP APL

What we really wanted was:

      1 2⊃3 4⊃<<5 6
┌───┬───┬─────┐
│1 2│3 4│┌───┐│
│   │   ││5 6││
│   │   │└───┘│
└───┴───┴─────┘
Works in: SHARP APL

Link is different from Pair , as Pair simply encloses both arguments and always produces a length-2 vector, so it cannot be used to construct a long nested array of uniform depth like Link does.

External links

Documentation

References

  1. "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