Enlist: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(Created page with "{{Built-in|Enlist|∊}} is a primitive function which returns a simple vector of all simple scalar values in a possibly nested array. Enlist differs from [...")
 
(Disambiguate use in K and BQN)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Built-in|Enlist|∊}} is a [[primitive function]] which returns a [[simple]] [[vector]] of all simple [[scalar]] values in a possibly [[nested array]]. Enlist differs from [[Ravel]] in that Enlist flattens over all layers of nesting, while Ravel flattens only the outermost layer. Enlist shares its [[glyph]] <source lang=apl inline>∊</source> with the dyadic function [[Membership]].
:''For the K and BQN function that creates a one-element list containing its argument, see [[Pair]].''
 
{{Built-in|Enlist|∊}} is a [[primitive function]] which returns a [[simple]] [[vector]] of all simple [[scalar]] values in a possibly [[nested array]]. Enlist differs from [[Ravel]] in that Enlist flattens over all layers of nesting, while Ravel flattens only the outermost layer. Enlist shares its [[glyph]] <syntaxhighlight lang=apl inline>∊</syntaxhighlight> with the dyadic function [[Membership]].
== Support ==
[[APL2]] IUP had <syntaxhighlight lang=apl inline>∊</syntaxhighlight> mean [[Type]]<ref>Graham, Alan. [https://dl.acm.org/doi/pdf/10.1145/22008.22033#page=4 Idioms and Problem Solving Techniques in APL2; Appendix - APL2 Idiom List: 9. Type]. [[APL86]].</ref> and [[Dyalog APL]] originally did too. However, by the time [[IBM]] released APL2, <syntaxhighlight lang=apl inline>∊</syntaxhighlight> (which stood for '''''e''''' in ''prototypical '''e'''lement'') was repurposed for [[Enlist]] (<syntaxhighlight lang=apl inline>∊</syntaxhighlight> being for '''''e''''' in '''''e'''nlist''). Thus, Dyalog left the Type meaning in place only when [[migration level]] is 0, while setting it to 1 (the default) or higher follows IBM's replacement meaning.


== Examples ==
== Examples ==
Line 5: Line 9:
Enlist is equivalent to a [[wikipedia:depth-first search|depth-first search]] collecting all simple scalars, where each layer (which in turn can be of any rank) is traversed in [[ravel order]].
Enlist is equivalent to a [[wikipedia:depth-first search|depth-first search]] collecting all simple scalars, where each layer (which in turn can be of any rank) is traversed in [[ravel order]].


<source lang=apl>
<syntaxhighlight lang=apl>
       ⎕←MAT←2 2⍴'MISS' 'IS' 'SIP' 'PI'
       ⎕←MAT←2 2⍴'MISS' 'IS' 'SIP' 'PI'
┌────┬──┐
┌────┬──┐
Line 23: Line 27:
       ∊M
       ∊M
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
</source>
</syntaxhighlight>


Enlist acts like [[Ravel]] for simple arrays. This includes simple scalars, where the result is a [[singleton]] vector.
Enlist acts like [[Ravel]] for simple arrays. This includes simple scalars, where the result is a [[singleton]] vector.


<source lang=apl>
<syntaxhighlight lang=apl>
       ⎕←mat←4 4⍴⍳16
       ⎕←mat←4 4⍴⍳16
  1  2  3  4
  1  2  3  4
Line 42: Line 46:
       ⍴∊3                    ⍝ It's now a vector
       ⍴∊3                    ⍝ It's now a vector
1
1
</source>
</syntaxhighlight>


== External links ==
== External links ==
Line 52: Line 56:
=== Documentation ===
=== Documentation ===


* [http://help.dyalog.com/latest/#Language/Primitive%20Functions/Enlist.htm Dyalog]
* [https://help.dyalog.com/latest/#Language/Primitive%20Functions/Enlist.htm Dyalog]
* [http://microapl.com/apl_help/ch_020_020_370.htm APLX]
* [http://microapl.com/apl_help/ch_020_020_370.htm APLX]


{{APL built-ins}}[[Category:Primitive functions]]
{{APL built-ins}}[[Category:Primitive functions]]

Latest revision as of 15:32, 6 March 2024

For the K and BQN function that creates a one-element list containing its argument, see Pair.

Enlist () is a primitive function which returns a simple vector of all simple scalar values in a possibly nested array. Enlist differs from Ravel in that Enlist flattens over all layers of nesting, while Ravel flattens only the outermost layer. Enlist shares its glyph with the dyadic function Membership.

Support

APL2 IUP had mean Type[1] and Dyalog APL originally did too. However, by the time IBM released APL2, (which stood for e in prototypical element) was repurposed for Enlist ( being for e in enlist). Thus, Dyalog left the Type meaning in place only when migration level is 0, while setting it to 1 (the default) or higher follows IBM's replacement meaning.

Examples

Enlist is equivalent to a depth-first search collecting all simple scalars, where each layer (which in turn can be of any rank) is traversed in ravel order.

      ⎕←MAT←2 2⍴'MISS' 'IS' 'SIP' 'PI'
┌────┬──┐
│MISS│IS│
├────┼──┤
│SIP │PI│
└────┴──┘
      ∊MAT
MISSISSIPPI

      ⎕←M←1 (2 2⍴2 3 4 5) (6(7 8))
┌─┬───┬───────┐
│1│2 3│┌─┬───┐│
│ │4 5││6│7 8││
│ │   │└─┴───┘│
└─┴───┴───────┘
      ∊M
1 2 3 4 5 6 7 8

Enlist acts like Ravel for simple arrays. This includes simple scalars, where the result is a singleton vector.

      ⎕←mat←4 4⍴⍳16
 1  2  3  4
 5  6  7  8
 9 10 11 12
13 14 15 16
      (,mat)≡∊mat
1

      ∊3
3
      3 ≡ ∊3                  ⍝ Not the same
0
      ⍴∊3                     ⍝ It's now a vector
1

External links

Lessons

Documentation


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