Skip to content

Instantly share code, notes, and snippets.

@xpqz
Created December 4, 2020 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpqz/a614fb8c4643b05448fded4c9b2be6f6 to your computer and use it in GitHub Desktop.
Save xpqz/a614fb8c4643b05448fded4c9b2be6f6 to your computer and use it in GitHub Desktop.
Noddy dictionary ns for Dyalog
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