1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"949.43">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000000}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 14.0px Helvetica
}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica
; min-height: 14.0px}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #bf0000}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000000; min-height: 12.0px}
18 span
.s1
{font: 18.0px Helvetica
}
19 span
.s2
{color: #001bb9}
20 span
.s3
{color: #0000ff}
21 span
.s4
{color: #007300}
22 span
.s5
{color: #0000bf}
23 span
.Apple-tab-span
{white-space:pre
}
27 <p class=
"p1"><span class=
"s1"><b>Association
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b></span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>relate two objects
<span class=
"Apple-converted-space"> </span></b></p>
28 <p class=
"p2"><br></p>
29 <p class=
"p1"><b>Inherits from:
</b><a href=
"../Core/Object.html"><span class=
"s2"><b>Object
</b></span></a><b> :
</b><a href=
"../Math/Magnitude.html"><span class=
"s3"><b>Magnitude
</b></span></a></p>
30 <p class=
"p2"><br></p>
31 <p class=
"p1">Associates a key with a value.
<span class=
"Apple-converted-space"> </span></p>
32 <p class=
"p1">Associations can be created via the -
> operator which is defined in class
<a href=
"../Core/Object.html"><span class=
"s3">Object
</span></a>.
</p>
33 <p class=
"p2"><br></p>
34 <p class=
"p1">Associations are used internally in
<a href=
"Dictionary.html"><span class=
"s3">Dictionary
</span></a></p>
35 <p class=
"p2"><br></p>
37 <p class=
"p3">x =
<span class=
"s4">'name'
</span> -
> 100;
</p>
38 <p class=
"p3">x.postln;
</p>
40 <p class=
"p2"><br></p>
41 <p class=
"p4"><b>Accessing
</b></p>
42 <p class=
"p2"><br></p>
43 <p class=
"p1"><b><>key
</b></p>
44 <p class=
"p2"><br></p>
45 <p class=
"p1">the key object.
</p>
46 <p class=
"p2"><br></p>
47 <p class=
"p1"><b><>value
</b></p>
48 <p class=
"p2"><br></p>
49 <p class=
"p1">the value object.
</p>
50 <p class=
"p2"><br></p>
51 <p class=
"p2"><br></p>
52 <p class=
"p4"><b>Creation
</b></p>
53 <p class=
"p2"><br></p>
54 <p class=
"p1"><b>*new(key, value)
</b></p>
55 <p class=
"p2"><br></p>
56 <p class=
"p1">Create an Association between two objects.
</p>
57 <p class=
"p1"><b>key
</b> - any object.
<span class=
"Apple-converted-space"> </span></p>
58 <p class=
"p1"><b>value
</b> - any object.
</p>
59 <p class=
"p2"><br></p>
60 <p class=
"p2"><br></p>
61 <p class=
"p4"><b>Testing
</b></p>
62 <p class=
"p2"><br></p>
63 <p class=
"p1"><b>== anAssociation
</b></p>
64 <p class=
"p2"><br></p>
65 <p class=
"p1">Compare the keys of two Associations.
</p>
66 <p class=
"p2"><br></p>
67 <p class=
"p1"><b>< anAssociation
</b></p>
68 <p class=
"p2"><br></p>
69 <p class=
"p1">Compare the keys of two Associations.
</p>
70 <p class=
"p2"><br></p>
71 <p class=
"p1"><b>hash
</b></p>
72 <p class=
"p2"><br></p>
73 <p class=
"p1">Compute the hash value of the Association.
</p>
74 <p class=
"p2"><br></p>
75 <p class=
"p2"><br></p>
76 <p class=
"p2"><br></p>
77 <p class=
"p4"><b>Writing to streams
</b></p>
78 <p class=
"p2"><br></p>
79 <p class=
"p1"><b>printOn(stream)
</b></p>
80 <p class=
"p2"><br></p>
81 <p class=
"p1">Write a string representation to the stream.
</p>
82 <p class=
"p2"><br></p>
83 <p class=
"p1"><b>storeOn(stream)
</b></p>
84 <p class=
"p2"><br></p>
85 <p class=
"p1">Write a compileable string representation to the stream.
</p>
86 <p class=
"p2"><br></p>
87 <p class=
"p2"><br></p>
88 <p class=
"p2"><br></p>
89 <p class=
"p2"><br></p>
90 <p class=
"p5"><b>Examples
</b></p>
91 <p class=
"p6"><br></p>
92 <p class=
"p7">// associations can be a good way to store named data in order:
</p>
94 <p class=
"p3">a = [
<span class=
"s4">\x
</span> -
> 700,
<span class=
"s4">\y
</span> -
> 200,
<span class=
"s4">\z
</span> -
> 900];
</p>
95 <p class=
"p8"><br></p>
96 <p class=
"p3">fork {
</p>
97 <p class=
"p3"><span class=
"Apple-tab-span"> </span>a.do {
<span class=
"s5">|assoc|
</span></p>
98 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>assoc.key.postln;
</p>
99 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>assoc.value.postln;
</p>
100 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>(freq: assoc.value).play;
</p>
101 <p class=
"p3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>2.wait;
</p>
102 <p class=
"p3"><span class=
"Apple-tab-span"> </span>}
</p>
105 <p class=
"p8"><br></p>
106 <p class=
"p8"><br></p>