Enlist: Difference between revisions
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 [...") |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
(2 intermediate revisions by the same 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]] < | {{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]]. | ||
== Examples == | == Examples == | ||
Line 5: | Line 5: | ||
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]]. | ||
< | <syntaxhighlight lang=apl> | ||
⎕←MAT←2 2⍴'MISS' 'IS' 'SIP' 'PI' | ⎕←MAT←2 2⍴'MISS' 'IS' 'SIP' 'PI' | ||
┌────┬──┐ | ┌────┬──┐ | ||
Line 23: | Line 23: | ||
∊M | ∊M | ||
1 2 3 4 5 6 7 8 | 1 2 3 4 5 6 7 8 | ||
</ | </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. | ||
< | <syntaxhighlight lang=apl> | ||
⎕←mat←4 4⍴⍳16 | ⎕←mat←4 4⍴⍳16 | ||
1 2 3 4 | 1 2 3 4 | ||
Line 42: | Line 42: | ||
⍴∊3 ⍝ It's now a vector | ⍴∊3 ⍝ It's now a vector | ||
1 | 1 | ||
</ | </syntaxhighlight> | ||
== External links == | == External links == | ||
Line 52: | Line 52: | ||
=== Documentation === | === Documentation === | ||
* [ | * [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]] |
Revision as of 22:04, 10 September 2022
∊
|
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.
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