memo{                                        ⍝ Function memoization.
    ⍺←⊢                                       ⍝ ambi-valent.
    (⊂⍺ ⍵ ⍵)∊⍵⍵.keys:⍵⍵.((keys⍳⊂⍺ ⍵ ⍵)vals)  ⍝ arg(s) known: fetch result.
    ↑⍬⍴⍵⍵.(vals keys),∘⊂←(⍺ ⍺⍺ ⍵)(⍺ ⍵ ⍵)      ⍝ otherwise: calc & extend cache.
}

code_colours

test script

Back to: notes

Back to: Workspaces