subs←{⎕ML←1                             ⍝ Vector substitution.
    fs ts←≢¨fm to←⍺                     ⍝ old and new vectors and sizes
    1≡≡⍺:to@(fm∘=)⍵                     ⍝ special case: simple scalar subs
    0=⍴⍴⍵:⊃(⍵≡fm)⌽⍵(to)                ⍝ special case: scalar argt
    leadfs↑1                           ⍝ leading mask
    (fm⍷⍵){                             ⍝ hits mask
        ~1∊⍺:⍵                          ⍝ early out if no match
        ts↓↑,/{to,fs↓⍵}¨(lead,⍺)fm,⍵   ⍝ cut and pasted new for old
    }⍤1⊢⍵                               ⍝ apply to vectors

test script

Back to: notes

Back to: Workspaces