Selective assignment

From APL Wiki
Revision as of 01:53, 18 October 2024 by Marshall (talk | contribs) (Created page with "'''Selective assignment''' is a form of assignment that is able to modify portions of arrays selected by functions using ordinary APL syntax. In APL2, it is defined as a general form that unifies ordinary assignment, indexed assignment, and stranded assignment. Dyalog APL, APLX, and APL\iv feature more limited versions restricted to a single modified array. Structural Under provides similar functionality in some dialects. The core concept...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Selective assignment is a form of assignment that is able to modify portions of arrays selected by functions using ordinary APL syntax. In APL2, it is defined as a general form that unifies ordinary assignment, indexed assignment, and stranded assignment. Dyalog APL, APLX, and APL\iv feature more limited versions restricted to a single modified array. Structural Under provides similar functionality in some dialects.

The core concept of selective assignment is that an APL expression acting on an existing array is written in parentheses on the left hand side of an assignment. The assignment acts to place the value on the right-hand side into the positions selected by that expression. It's often the case that evaluating the left-hand side then reproduces that value, although this is not guaranteed (for example (,A)←5 is allowed, although ,A can only ever be a vector and not a simple scalar).

      A ← 3 4⍴0
      (1 1⍉2 ¯2↑A) ← 1 2  ⍝ Selective assignment
      A
0 0 1 0
0 0 0 2
0 0 0 0

      1 1⍉2 ¯2↑A
1 2

APL2 allows any number of arrays to be assigned, with operations like stranding and Catenate allowed in the assignment target. A modification of ordinary evaluation is suggested for making sense of the left-hand side of such an assignment. The change is that when a name is reached, its value remains associated with the name, and furthermore, when acted on by a selective function, the result records where its items come from. The granularity of an "item" depends on what selective functions have been applied; for example, when Ravel is applied to an array, this array is expanded into elements, and its shape can no longer be changed by the assignment. After evaluating the left-hand side in this way, provided it was in fact derived by selection from target arrays, values from the right-hand side can then be placed into corresponding locations, matching the two using a type of conformability.[1]

External links

  • APL Interpreter by Lucas Scharenbroch includes a simple form of selective assignment.

Documentation

References

APL syntax [edit]
General Comparison with traditional mathematicsPrecedenceTacit programming (Train, Hook, Split composition)
Array Numeric literalStringStrand notationObject literalArray notation (design considerations)
Function ArgumentFunction valenceDerived functionDerived operatorNiladic functionMonadic functionDyadic functionAmbivalent functionDefined function (traditional)DfnFunction train
Operator OperandOperator valenceTradopDopDerived operator
Assignment MultipleIndexedSelectiveModified
Other Function axisBracket indexingBranchStatement separatorQuad nameSystem commandUser commandKeywordDot notationFunction-operator overloadingControl structureComment