]box on ]rows on -style=cut -fns=on )copy dfns lcase pco tc at 40 0⍴0 ⍝ throw some blank lines ⍝ Dyadic operator @ is a functional alternative to indexed assignment ⍝ History: merge(2012) → fusion(2015) → at(2016) V←⍳5 ⋄ V[2 4]×←10 ⋄ V ⍝ ten-fold at 2 4 in 1..5 10(×@2 4)⍳5 ⍝ modifier @ selector ⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Left operand (×) is "modifier" 10 100(×@2 4)⍳5 ⍝ dyadic function × 10 100(⊣@2 4)⍳5 ⍝ dyadic function ⊣ (⌽@2 4)'Space' ⍝ monadic function ⌽ [F@A] ('nk'@2 4)'Space' ⍝ array value 'nk' [A@A] ⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Right operand (2 4) is "selector" ('*'@2 4) 5↑⎕A ⍝ selector is an array value: 2 4 '*'@(∊∘'AEIOU') ⎕A ⍝ selector is a bool-returning fn [A@F] lcase@((~∊)∘'AEIOU') ⎕A ⍝ ditto with function modifier: [F@F] ⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Higher rank arguments M←5 5⍴⍳25 ⋄ M[2 4;]←2 5⍴⎕A ⋄ M ⍝ traditional major-cell assignment (2 5⍴⎕A)@2 4 ⊢5 5⍴⍳25 ⍝ simple selector: major cells (⍉2 5⍴⎕A)⊣@2 4⍤1 ⊢5 5⍴⍳25 ⍝ rank ⍤ for cols ⌽@2 4 ⊢5 5⍴⍳25 ⍝ zigzag: alternate rows reversed ⌽tc@2 4 ⊢5 5⍴⍳25 ⍝ showing trace (tc) of modifier function '*'@(2⍴¨⍳3) ⊢5 5⍴⍳25 ⍝ nested: choose indexing '⌽⍉'@(1 5)(2 2)⊢'hello' 'world' ⍝ nested: reach indexing 10×@2 4⍣2 ⍳5 ⍝ power: f@g⍣n → f⍣n@g 10×@2 4⍣¯1 ⍳5 ⍝ inverse: f@g⍣¯1 → f⍣¯1@g ⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝ Boolean selection: scatter-point 100×@(2∘|) 5 5⍴⍳25 ⍝ 100-fold at alternate items '*'@(0∘pco)5 5⍴⍳25 ⍝ prime numbers ⍝ Summary: ⍝ Tool-of-thought: denotative programming. ⍝ Generally shorter expressions. ⍝ Avoid *requirement* to name subject value: (bexp/NAME)←... ⍝ Flexible: can be embedded as a sub-expression. ⍝ Applicable by operators: each, rank, ... ⍝ ⍝ Implementation challenges: ⍝ Take advantage of low reference counts to avoid copyng: ⍝ U←(1@2) V+3 ⍝ overwrite 2nd item of V+3 as its refcount is 1 ⍝ U←(1@2) V ⍝ can't overwrite V, as U≢V ⍝ (1@2) ⍵ ⍝ can overwrite ⍵ if its refcount is 2 ⍝ ⍵+(1@2) ⍵ ⍝ can't (easily) overwrite ⍵ ⍝ ⍝ "at" model, discussion, examples: Google[dyalog item substitution]