Uses of ::= in core.
[cslatevm.git] / src / core / association.slate
blob9100e6e1460493941dcdfce216ea71b6a8077719
2 prototypes ensureNamespace: #collections &delegate: True.
4 "we cannot use the &slots: argument until association is defined"
5 collections define: #LookupKey &parents: {Comparable}.
6 LookupKey addSlot: #key.
8 "A LookupKey implements the fundamental protocol required by
9 the key in a key-value assocation (see Association)."
11 x@(LookupKey traits) < y@(LookupKey traits)
13   x key < y key
16 x@(LookupKey traits) = y@(LookupKey traits)
18   x key = y key
21 x@(LookupKey traits) hash
23   x key hash
26 collections define: #Association &parents: {LookupKey}.
27 Association addSlot: #value.
29 "An Association designates a mapping from a single key to a
30 single value.  The key must implement <, =, and hash.  
32 TODO: Explain any requirements for keys.  Why must keys be Comparable.
34 Creation examples:
35  Assocation newFrom: key to: value.
36  key -> value.
38 Note that Association is not currently used in the 
39 implementation of Dictionary.  This is because a Dictionary
40 implemented as a single collection of Associations allows
41 the possibility of altering the individual Associations
42 without the Dictionary being notified of the changes.  This
43 can break a dictionary implementation due to optimization
44 associations such as order based on the key value."
46 x@(Root traits) -> y
47 "Create and return a new association mapping x to y."
48 [Association cloneSettingSlots: #{#key. #value} to: {x. y}].
50 x@(Association traits) newFrom: key to: value
51 [x cloneSettingSlots: #{#key. #value} to: {x. y}].
53 x@(Association traits) = y@(Association traits)
54 [resend /\ [x value = y value]].
56 x@(Association traits) hash
57 [resend * x value hashMultiply].
59 x@(Root traits) define: assoc@(Association traits)
61   x addImmutableSlot: assoc key valued: assoc value.
62   x atSlotNamed: assoc key