Some functions in APL can be used to select portions of an array. When associated with assignment, they can be used to assign values to portions of such array.
Bracket indexing is the easiest example.
TAB← 2 3 ⍴⍳ 6 TAB[ 2 ; 1 ]← 8
Let's assign the first three elements of a vector by using the Take (dyadic ↑ ) function.
VEC←⍳ 5 ( 3 ↑VEC)← 'ABC' 8 ⎕CR VEC
┌→──────┐ │ABC 4 5│ └───────┘
Let's use the Ravel (monadic , ) on a matrix to assign a new vector value to it:
MAT← 3 4 ⍴ 'ABCDEFGHIJKL' (,MAT)← 'NEW DATAHERE' ⍝ Ravelled matrix appears as a vector 8 ⎕CR MAT ⍝ Assignment occurs in matrix itself
┌→───┐ ↓NEW │ │DATA│ │HERE│ └────┘
Now let's combine Compression (dyadic / ) and Ravel (monadic , ) to select all A's on the matrix, and replace them by asterisk:
... continue reading