Skip to content

Associations

$ wo '<|"Green" -> 2, "Red" -> 1|>'
<|Green -> 2, Red -> 1|>
$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>'
<|Green -> 2, Red -> 1|>

Access values in associations

$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; myHash[["Green"]]'
2
$ wo 'myHash = <|1 -> "Red", 2 -> "Green"|>; myHash[[1]]'
Red
$ wo 'assoc = <|"a" -> True, "b" -> False|>; assoc[["b"]]'
False

Calling an association is a lookup, and a lookup composes: each result is itself callable, and the multi-argument form walks the same chain.

$ wo 'a = <|"x" -> <|"y" -> 3|>|>; {a["x"]["y"], a["x", "y"]}'
{3, 3}

A key no association holds reports itself:

$ wo 'a = <|"x" -> <|"y" -> 3|>|>; a["x", "nope"]'
Missing[KeyAbsent, nope]

Update Values

$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; myHash[["Green"]] = 5; myHash'
<|Green -> 5, Red -> 1|>

Add Values

$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; myHash[["Puce"]] = 3.5; myHash'
<|Green -> 2, Red -> 1, Puce -> 3.5|>

Additional Functions