Difference between revisions of "From"
Line 1:  Line 1:  
−  {{BuiltinSelect⊇}} (jokingly referred to as ''Sane Indexing'') is a [[primitive function]] that allows selecting multiple [[major cell]]s using indices of the cells. It is equivalent to <source lang=apl inline>⌷⍨∘⊂⍨</source> and <source lang=apl inline>⌷⍤0 ∞</source>, only providing a neater notation for such a fundamental concept. It was introduced in [[Extended Dyalog APL]], and then adopted into [[dzaima/APL]] and [[KAP]].  +  {{BuiltinSelect⊇}} ([[humourjokingly]] referred to as ''Sane Indexing'') is a [[primitive function]] that allows selecting multiple [[major cell]]s using indices of the cells. It is equivalent to <source lang=apl inline>⌷⍨∘⊂⍨</source> and <source lang=apl inline>⌷⍤0 ∞</source>, only providing a neater notation for such a fundamental concept. It was introduced in [[Extended Dyalog APL]], and then adopted into [[dzaima/APL]] and [[KAP]]. 
== Common usage ==  == Common usage ==  
Line 19:  Line 19:  
</source>{{Works in[[dzaima/APL]], [[Extended Dyalog APL]]}}  </source>{{Works in[[dzaima/APL]], [[Extended Dyalog APL]]}}  
== Potential extension ==  == Potential extension ==  
−  Select can be defined as <source lang=apl inline>⌷⍨∘⊃⍨⍤0 ∞</source> thus allowing both the above usage and "scatter point indexing":  +  Select can be defined as <source lang=apl inline>⌷⍨∘⊃⍨⍤0 ∞</source> thus allowing both the above usage and "scatter point indexing":<ref>[[Richard Park]]. [https://dyalog.tv/Webinar/?v=AgYDvSF2FfU Selecting from Arrays]. [[Dyalog Webinar]]. 16 Apr 2020. (Presented in the form <source lang=apl inline>((⊃⊣)⌷⊢)⍤0 99</source>.)</ref> 
<source lang=apl>  <source lang=apl>  
1 4 3 ⊇ 4 4⍴⎕A  1 4 3 ⊇ 4 4⍴⎕A  
Line 32:  Line 32:  
* [[Bracket indexing]]  * [[Bracket indexing]]  
* [[Pick]]  * [[Pick]]  
+  == References ==  
+  <references/>  
{{APL builtins}}[[Category:Primitive functions]]  {{APL builtins}}[[Category:Primitive functions]] 
Revision as of 06:32, 11 May 2021
⊇

Select (⊇
) (jokingly referred to as Sane Indexing) is a primitive function that allows selecting multiple major cells using indices of the cells. It is equivalent to ⌷⍨∘⊂⍨
and ⌷⍤0 ∞
, only providing a neater notation for such a fundamental concept. It was introduced in Extended Dyalog APL, and then adopted into dzaima/APL and KAP.
Common usage
Select is commonly used to reorder the major cells of an array. For example, the following shuffles any array into random order:
Shuffle←?⍨∘≢⊇⊢
Shuffle 'abcdef'
fbdcea
Without Select, one would have to write Shuffle←⊢⌷⍨∘⊂?⍨∘≢
.
In a case where the left argument is a permutation vector for the right argument, the functionality can rightfully be called Permute.
Select especially cleans up expressions for reordering. An ascending sort can be represented as ⍋⊇⊢
and "sort by" can be written as ⊇⍨∘⍋
:
'abcde' ⊇⍨∘⍋ 3 1 4 1 5
bdace
Potential extension
Select can be defined as ⌷⍨∘⊃⍨⍤0 ∞
thus allowing both the above usage and "scatter point indexing":^{[1]}
1 4 3 ⊇ 4 4⍴⎕A
ABCD
MNOP
IJKL
(1 1)(4 4)(3 4) ⊇ 4 4⍴⎕A
APL
See also
References
 ↑ Richard Park. Selecting from Arrays. Dyalog Webinar. 16 Apr 2020. (Presented in the form
((⊃⊣)⌷⊢)⍤0 99
.)