atomo-0.4: prelude/association.atomo
Association = Object clone
a -> b := Association clone do: { from = a; to = b }
(a: Association) pretty :=
{ a from pretty-parens <+> text: "->" <+> a to pretty-parens
} doc
(a: Association) == (b: Association) :=
a from == b from && a to == b to
[] lookup: _ := @none
(a . as) lookup: k :=
if: (k == a from)
then: { @(ok: a to) }
else: { as lookup: k }
[] find: _ := @none
(a . as) find: k :=
if: (k == a from)
then: { @(ok: a) }
else: { as find: k }
[] set: k to: v := [k -> v]
(a . as) set: k to: v :=
if: (k == a from)
then: { (k -> v) . as }
else: { a . (as set: k to: v) }