Created
December 4, 2020 15:07
-
-
Save xpqz/a614fb8c4643b05448fded4c9b2be6f6 to your computer and use it in GitHub Desktop.
Noddy dictionary ns for Dyalog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Append←{⎕IO←0 ⍝ Given a vector of keys and a vector of vals append vals | |
⍺∘{ | |
(k v)←⍵ | |
i←⍺.Keys⍳k | |
i=≢⍺.Keys:1⊣⍺.Keys,←k⊣⍺.Vals,←v ⍝ New key | |
⍺.Vals[i],←v ⍝ Replace existing | |
0 | |
}¨↓⍉↑⍵ | |
} | |
Create←{ | |
keys←(1500⌶),⍺ | |
vals←,⍵ | |
{⍵⊣⍵.(Vals Keys Default)←vals keys ⍬}⎕NS'' | |
} | |
Get←{ | |
~⍵ In ⍺:⍺.Default | |
⍺.Vals[⍺.Keys⍳⍵] | |
} | |
In←{⍺∊⍵.Keys} | |
Set←{⎕IO←0 ⍝ Upsert ht ⍺ given a vector of keys and a vector of vals | |
⍺∘{ | |
k←0⌷⍵ ⋄ v←1⌷⍵ | |
i←⍺.Keys⍳k | |
i=≢⍺.Keys:1⊣⍺.Keys,←k⊣⍺.Vals,←v ⍝ New key | |
⍺.Vals[i]←v ⍝ Replace existing | |
0 | |
}¨↓⍉↑⍵ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment