Difference between revisions of "From"

From APL Wiki
Jump to navigation Jump to search
Line 21: Line 21:
 
== Extensions ==
 
== Extensions ==
 
=== Scatter-point ===
 
=== Scatter-point ===
In [[A Dictionary of APL]] and [[J]], a boxed left argument indicates that each [[element]] will be used independently to select a [[cell]] of the argument. The behavior on a single element is very similar to APL's [[Index (function)|Index]] function. <source lang=j inline>{</source> has a left [[Function rank|rank]] of 0, so that results are [[mix]]ed together and those with different shapes may be padded with [[fill]]s.
+
In [[A Dictionary of APL]], [[J]], and [[SAX]], a boxed left argument indicates that each [[element]] will be used independently to select a [[cell]] of the argument. The behavior on a single element is very similar to APL's [[Index (function)|Index]] function. <source lang=j inline>{</source> has a left [[Function rank|rank]] of 0, so that results are [[mix]]ed together and those with different shapes may be padded with [[fill]]s.
 
<source lang=j>
 
<source lang=j>
 
   ]a =. 4 4$(a.i.'A')}.a.
 
   ]a =. 4 4$(a.i.'A')}.a.

Revision as of 15:32, 13 May 2021

{

From ({) or Select (, or in BQN) (sometimes humourously called Sane Indexing) is a primitive function that selects multiple major cells of its right argument using an array of indices given by its left. The primitive often offers additional functionality for a nested left argument, which varies from one language to another. It appears in J, Extended Dyalog APL, dzaima/APL, KAP, and BQN.

Common usage

Select is commonly used to reorder the major cells of an array. For example, the following shuffles any array into random order:

Try it online!

      Shuffle?⍨∘
      Shuffle 'abcdef'
fbdcea

Without Select, one would have to write Shuffle⊢⌷⍨∘⊂?⍨∘. In this meaning, Select might be written as ⍨∘ or 0 99 in Dyalog APL (where 99 exceeds the system's maximum array rank).

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 ⍨∘:

Try it online!

      'abcde' ⍨∘ 3 1 4 1 5
bdace

Extensions

Scatter-point

In A Dictionary of APL, J, and SAX, a boxed left argument indicates that each element will be used independently to select a cell of the argument. The behavior on a single element is very similar to APL's Index function. { has a left rank of 0, so that results are mixed together and those with different shapes may be padded with fills.

   ]a =. 4 4$(a.i.'A')}.a.
ABCD
EFGH
IJKL
MNOP
   0 3 2 { a
ABCD
MNOP
IJKL
   (0 0;3 3;2 3) { a
APL
Works in: J

In APL this extension can be defined as ⍨∘⍨⍤0 thus allowing both the above usage and "scatter point indexing":[1]

History

From ({) was introduced in 1986 by A Dictionary of APL, with the same meaning now used in J. This description introduced the characteristic feature of selection of multiple cells simultaneously, as well as the pairing with monadic Catalogue, scatter-point indexing, negative indices, and the ability to exclude rather than include indices using a third level of boxing. Roger Hui expressed his support for the new definition with a presentation at the next APL conference[2], and it was included in J from the earliest drafts in 1990—a limited version had even appeared in Arthur Whitney's one-page interpreter prototype.

The name Select and glyph were introduced by Extended Dyalog APL, and subsequently adopted by dzaima/APL and KAP.

BQN uses the name Select like Extended Dyalog APL but takes the direction of the glyph , as well as negative indexing, from J. For a nested left argument it uses a new extension: instead of viewing nesting as elaboration of each element of the left argument, it instead treats it as providing a list of left arguments to select from multiple axes of the right argument. This extension provides the functionality of APL's Index not by requiring the left argument as a whole to be enclosed but by requiring that each of its elements be an array.

See also

External links

Documentation

References

  1. Richard Park. Selecting from Arrays. Dyalog Webinar. 16 Apr 2020. (Presented in the form ((⊃⊣)⌷⊢)0 99.)
  2. Roger Hui. Some Uses of { and } at APL87.
APL built-ins [edit]
Primitive functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentitySelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndex
Selector Index generatorGradeIndex OfInterval IndexIndicesDeal
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Primitive operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-beamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Atop, Over) ∙ Inner ProductPowerAtUnderRankDepthVariantStencilCut (J)
Quad names
Arrays Index originMigration levelAtomic vector
Functions Name classCase convertUnicode convert
Operators SearchReplace