At: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(Add At operator page)
 
(correction for bools)
Line 5: Line 5:
A call to At is of the form <source lang=apl inline>X(f@g)Y</source> where <source lang=apl inline>X</source> is optional.  
A call to At is of the form <source lang=apl inline>X(f@g)Y</source> where <source lang=apl inline>X</source> is optional.  
* <source lang=apl inline>g</source>  specifies the indices of the right argument that should be modified.
* <source lang=apl inline>g</source>  specifies the indices of the right argument that should be modified.
** '''Function''': Must apply to <source lang=apl inline>Y</source> , and return a boolean array of positions which should be modified.
** '''Function''': Must apply to <source lang=apl inline>Y</source> , and return a boolean array with ones at positions that should be modified.
** '''Array''': Specifies the indices directly. If this is a scalar, it is repeated as necessary.
** '''Array''': Specifies the indices directly. If this is a scalar, it is repeated as necessary.
* <source lang=apl inline>f</source>  specifies what happens to the elements at those positions.
* <source lang=apl inline>f</source>  specifies what happens to the elements at those positions.

Revision as of 09:13, 27 April 2022

@

At (@) is a primitive dyadic operator that is similar to J and K's Amend in functionality. In Dyalog APL, At handles a subset of the cases of the Under operator that pertain to modifying elements at specific positions in an array.

Description

At takes two operator arguments, and it has many overloads based on the types of its arguments. A call to At is of the form X(f@g)Y where X is optional.

  • g specifies the indices of the right argument that should be modified.
    • Function: Must apply to Y , and return a boolean array with ones at positions that should be modified.
    • Array: Specifies the indices directly. If this is a scalar, it is repeated as necessary.
  • f specifies what happens to the elements at those positions.
    • Function: Applies to all the selected elements at once. If X is given, then it is bound to this function (X∘f ).
    • Array: Replaces the selected elements.

Examples

      ⍝ Simple replacement
      (1 2 3@4 5 6)7 5 4 10 3 6 9 2 1 8
7 5 4 1 2 3 9 2 1 8
      (0@2 4) 1 2 3 4 5
1 0 3 0 5
      ⍝ f is a function
      10 (×@2 4) 1 2 3 4 5
1 20 3 40 5
      (÷@2 4) 1 2 3 4 5
1 0.5 3 0.25 5
      ⍝ g is a function
      '*'@(2∘|) 1 2 3 4 5  ⍝ Boolean selection 1 0 1 0 1
* 2 * 4 *
      ⍝ f and g are functions
      10 (×@(≤∘3)) 3 1 4 1 5
30 10 4 10 5
      ⌽@(2∘|) 1 2 3 4 5  ⍝ Reversal of sub-array 1 3 5
5 2 3 4 1

See Also

Under

External Links

Lessons

APL Cultivation

Documentation

Publications

Prefix friendly @ by Aaron Hsu and Roger Hui


APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
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 axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)
Quad names Index originComparison toleranceMigration levelAtomic vector