4,499
edits
m (Text replacement - "</source>" to "</syntaxhighlight>") |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
Line 1: | Line 1: | ||
{{Built-in|Link|⊃}}, or < | {{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 < | 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]]. | ||
< | <syntaxhighlight lang=apl> | ||
1 2⊃3 4⊃5 6 | 1 2⊃3 4⊃5 6 | ||
┌───┬───┬───┐ | ┌───┬───┬───┐ | ||
Line 18: | Line 18: | ||
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: | ||
< | <syntaxhighlight lang=apl> | ||
(1 2⊃3 4)⊃5 6 | (1 2⊃3 4)⊃5 6 | ||
┌─────────┬───┐ | ┌─────────┬───┐ | ||
Line 29: | Line 29: | ||
Similarly, the chaining fails if the rightmost array is already nested: | Similarly, the chaining fails if the rightmost array is already nested: | ||
< | <syntaxhighlight lang=apl> | ||
1 2⊃3 4⊃<5 6 | 1 2⊃3 4⊃<5 6 | ||
┌───┬───┬───┐ | ┌───┬───┬───┐ | ||
Line 36: | Line 36: | ||
</syntaxhighlight>{{Works in|[[SHARP APL]]}} | </syntaxhighlight>{{Works in|[[SHARP APL]]}} | ||
What we really wanted was: | What we really wanted was: | ||
< | <syntaxhighlight lang=apl> | ||
1 2⊃3 4⊃<<5 6 | 1 2⊃3 4⊃<<5 6 | ||
┌───┬───┬─────┐ | ┌───┬───┬─────┐ | ||
Line 45: | Line 45: | ||
</syntaxhighlight>{{Works in|[[SHARP APL]]}} | </syntaxhighlight>{{Works in|[[SHARP APL]]}} | ||
Link is different from [[Pair]] < | 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 == |