At: Difference between revisions
No edit summary |
|||
Line 89: | Line 89: | ||
<tr> | <tr> | ||
<td>For example: | <td>For example: | ||
Replace all items of <apll>R</apll>: | Replace all of the items of <apll>R</apll> with <apll>¯1</apll>: | ||
<apll><pre> | <apll><pre> | ||
¯1@∘⍳2 3 | ¯1@∘⍳2 3 | ||
Line 102: | Line 102: | ||
</table> | </table> | ||
| | ||
===Function v. Variable=== | ===Function v. Variable=== | ||
Latest revision as of 17:16, 4 December 2023
At Derived Functions
The dyadic At operator is used to index assign into an array R, returning as the result the changed array. There are four separate cases, depending upon whether the two operands are Variables or Functions. The design of this operator is taken directly from the corresponding feature in Dyalog APL.
Variable v. Variable
|
||
For example:
Replace the 1st and last characters in a string with a string: (⊂'abra')@(1 5)'scads!' abra cad abra ! |
||
Replace the diagonal elements of a matrix:
'abcd'@(2/¨⍳4)4 4⍴⍳16 a 2 3 4 5 b 7 8 9 10 c 12 13 14 15 d |
||
This case is implemented via the anonymous function {A←⍵ ⋄ 1≥≡A:A⊣A[⊃⍵⍵⌷¨⊂⍳⍴A]←⍺⍺ ⋄ A[⍵⍵]←⍺⍺ ⋄ A}. |
Variable v. Function
|
||
For example:
Replace the prime numbers in R with a character: 'π'@{0π⍵}4 4⍴⍳16 1 π π 4 π 6 π 8 9 10 π 12 π 14 15 16 |
||
This case is implemented via the anonymous function {A←⍵ ⋄ A[⍸⍵⍵ A]←⍺⍺ ⋄ A}. |
Variable v. Jot
|
||
For example:
Replace all of the items of R with ¯1: ¯1@∘⍳2 3 ¯1 ¯1 ¯1 ¯1 ¯1 ¯1 |
||
This case is implemented via the anonymous function {A←⍵ ⋄ A[]←⍺⍺ ⋄ A}. |
Function v. Variable
|
||
For example:
Replace the diagonal elements of a matrix with their reciprocals: ÷@(2/¨⍳4)4 4⍴⍳16x 1 2 3 4 5 1r6 7 8 9 10 1r11 12 13 14 15 1r16 |
||
Replace the diagonal elements of a matrix with their duplicates:
2/¨@(2/¨⍳4)4 4⍴⍳16 1 1 2 3 4 5 6 6 7 8 9 10 11 11 12 13 14 15 16 16 |
||
This case is implemented via the anonymous function {⍺←⊢ ⋄ A←⍵ ⋄ 1≥≡A:A⊣A[B]←⍺ ⍺⍺ A[B]⊣B←⊃⍵⍵⌷¨⊂⍳⍴A ⋄ A[⍵⍵]←⍺ ⍺⍺ A[⍵⍵] ⋄ A}. |
Function v. Function
|
||
For example:
Replace composite numbers with their factors: π¨@{~0π⍵}4 4⍴⍳16 1 2 3 2 2 5 2 3 7 2 2 2 3 3 2 5 11 2 2 3 13 2 7 3 5 2 2 2 2 |
||
This case is implemented via the anonymous function {⍺←⊢ ⋄ A←⍵ ⋄ B←⍸⍵⍵ A ⋄ A[B]←⍺ ⍺⍺ A[B] ⋄ A}. |