4,577
edits
m (Text replacement - "</source>" to "</syntaxhighlight>") |
|||
(8 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
== Examples == | == Examples == | ||
An enclosed array is a [[scalar]], which is subject to [[scalar extension]]. This can be used to simulate [[Outer Product|outer product]] by a [[scalar function]] or one-sided [[Each]] (pair the entire right argument with each element of the left argument, or vice versa). A notable application of this behavior is the "chipmunk idiom" < | An enclosed array is a [[scalar]], which is subject to [[scalar extension]]. This can be used to simulate [[Outer Product|outer product]] by a [[scalar function]] or one-sided [[Each]] (pair the entire right argument with each element of the left argument, or vice versa). A notable application of this behavior is the "chipmunk idiom" <syntaxhighlight lang=apl inline>X⊃¨⊂Y</syntaxhighlight>, which simulates <syntaxhighlight lang=apl inline>Y[X]</syntaxhighlight> for (possibly nested) [[vector]] Y and [[simple]] X. | ||
< | <syntaxhighlight lang=apl> | ||
1 2 3+⊂4 5 6 ⍝ Computes (1+4 5 6)(2+4 5 6)(3+4 5 6) | 1 2 3+⊂4 5 6 ⍝ Computes (1+4 5 6)(2+4 5 6)(3+4 5 6) | ||
┌─────┬─────┬─────┐ | ┌─────┬─────┬─────┐ | ||
Line 20: | Line 20: | ||
│3 4│1 2│ | │3 4│1 2│ | ||
└───┴───┘ | └───┴───┘ | ||
</ | </syntaxhighlight> | ||
Enclose with function axis can be used to move one or more axes to an extra level of nesting. | Enclose with function axis can be used to move one or more axes to an extra level of nesting. | ||
< | <syntaxhighlight lang=apl> | ||
⎕←M←2 3 4⍴⎕A | ⎕←M←2 3 4⍴⎕A | ||
ABCD | ABCD | ||
Line 51: | Line 51: | ||
⍴⊃⊂[1 3]N ⍝ Shape of each element is the enclosed axes | ⍴⊃⊂[1 3]N ⍝ Shape of each element is the enclosed axes | ||
2 4 | 2 4 | ||
</ | </syntaxhighlight>{{Works in|[[Dyalog APL]]}} | ||
== Description == | == Description == | ||
With no [[function axis]], Enclose returns a [[scalar]] array whose only [[element]] is the argument. In the [[flat array model]] this means that the argument is placed in a [[box]], and the result is this box as a scalar. In the [[nested array model]] it can simply be viewed as creating a new array. However, if the argument is a [[simple scalar]], then the result will match the argument because nested array theory dicatates that simple scalars [[float]]. | |||
Enclose (without axis) is | == Properties == | ||
Enclose (without axis) is the [[inverse]] of both [[Mix]] and [[First]] in the sense that either of these undoes the additional nesting introduced by Enclose. | |||
== External links == | == External links == | ||
Line 63: | Line 65: | ||
=== Documentation === | === Documentation === | ||
* [ | * [https://help.dyalog.com/latest/#Language/Primitive%20Functions/Enclose.htm Dyalog], [https://help.dyalog.com/latest/#Language/Primitive%20Functions/Enclose%20with%20Axes.htm with axes] | ||
* [http://microapl.com/apl_help/ch_020_020_580.htm APLX] | * [http://microapl.com/apl_help/ch_020_020_580.htm APLX] | ||
* J [https://www.jsoftware.com/help/dictionary/d010.htm Vocabulary], [https://code.jsoftware.com/wiki/Vocabulary/lt NuVoc] | * J [https://www.jsoftware.com/help/dictionary/d010.htm Vocabulary], [https://code.jsoftware.com/wiki/Vocabulary/lt NuVoc] (as <syntaxhighlight lang=j inline><</syntaxhighlight>) | ||
* [https://mlochbaum.github.io/BQN/doc/enclose.html BQN] (as <code><</code>) | |||
{{APL built-ins}}[[Category:Primitive functions]] | {{APL built-ins}}[[Category:Primitive functions]] |