supernova: c++11 compile fixes
[supercollider.git] / Help / Core / Symbol.html
blob687d7a693f1063f73937cfac93ff2c27198c3943
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="1038.25">
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: 14.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #00831b}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
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 57.0px; text-indent: -57.0px; font: 12.0px Helvetica}
17 p.p8 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco}
18 p.p9 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; min-height: 12.0px}
19 p.p10 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; color: #00831c}
20 p.p11 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 14.0px Helvetica}
21 p.p12 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 14.0px Helvetica; min-height: 17.0px}
22 p.p13 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica; color: #1135f9}
23 p.p14 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica; color: #1135f9; min-height: 14.0px}
24 p.p15 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; color: #00831b}
25 p.p16 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; color: #00831c; min-height: 12.0px}
26 span.s1 {font: 18.0px Helvetica}
27 span.s2 {color: #1135f9}
28 span.s3 {color: #737373}
29 span.s4 {color: #00831b}
30 span.s5 {color: #00831c}
31 span.s6 {font: 12.0px Helvetica}
32 span.s7 {font: 9.0px Monaco}
33 span.s8 {font: 12.0px Helvetica; color: #000000}
34 span.s9 {color: #000000}
35 span.s10 {color: #0b28c6}
36 span.s11 {text-decoration: underline ; color: #0000ee}
37 span.s12 {color: #0b28c5}
38 span.Apple-tab-span {white-space:pre}
39 </style>
40 </head>
41 <body>
42 <p class="p1"><span class="s1"><b>Symbol<span class="Apple-tab-span"> </span></b></span><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>unique name</b></p>
43 <p class="p2"><br></p>
44 <p class="p1"><b>superclass: </b><a href="Object.html"><span class="s2"><b>Object</b></span></a></p>
45 <p class="p2"><br></p>
46 <p class="p1">A Symbol is a name that is guaranteed to be <b>unique</b>. They can be used to represent</p>
47 <p class="p1">symbolic constant values, Dictionary keys, etc.</p>
48 <p class="p2"><br></p>
49 <p class="p1">Symbols are represented syntactically as literals which are described in [<a href="../Language/Literals.html"><span class="s2">Literals</span></a>]</p>
50 <p class="p2"><br></p>
51 <p class="p2"><br></p>
52 <p class="p3"><b>Creating a Symbol</b></p>
53 <p class="p2"><br></p>
54 <p class="p1"><span class="Apple-tab-span"> </span>A symbol can be written by surrounding characters by single quotes (may include whitespace):</p>
55 <p class="p2"><br></p>
56 <p class="p4"><span class="Apple-tab-span"> </span>'foo bar'</p>
57 <p class="p2"><br></p>
58 <p class="p1"><span class="Apple-tab-span"> </span>Or by a preceeding backslash (then it may not include whitespace):</p>
59 <p class="p2"><br></p>
60 <p class="p4"><span class="Apple-tab-span"> </span>\foo</p>
61 <p class="p2"><br></p>
62 <p class="p1"><span class="Apple-tab-span"> </span>A String can be converted into a symbol:</p>
63 <p class="p2"><br></p>
64 <p class="p5"><span class="Apple-tab-span"> </span><span class="s3">"arbeit"</span>.scramble.asSymbol;</p>
65 <p class="p2"><br></p>
66 <p class="p2"><br></p>
67 <p class="p3"><b>Testing</b></p>
68 <p class="p6"><br></p>
69 <p class="p7"><b><span class="Apple-tab-span"> </span>isClassName / isMetaClassName</b></p>
70 <p class="p6"><span class="Apple-tab-span"> </span></p>
71 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Answer whether the symbol can be a class name / meta class name. This does not say if the class exists.</p>
72 <p class="p6"><span class="Apple-tab-span"> </span></p>
73 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">\Array</span>.isClassName;</p>
74 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">\Bauxite</span>.isClassName;</p>
75 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">\Meta_Array</span>.isMetaClassName;</p>
76 <p class="p6"><span class="Apple-tab-span"> </span></p>
77 <p class="p7"><span class="Apple-tab-span"> </span><b>isSetter</b></p>
78 <p class="p6"><span class="Apple-tab-span"> </span></p>
79 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Answer whether the symbol has a trailing underscore.</p>
80 <p class="p6"><span class="Apple-tab-span"> </span></p>
81 <p class="p8"><span class="s6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s4">'_action'</span>.isSetter;</p>
82 <p class="p9"><span class="Apple-tab-span"> </span></p>
83 <p class="p7"><span class="s7"><span class="Apple-tab-span"> </span></span><b>isPrimitiveName</b></p>
84 <p class="p6"><span class="Apple-tab-span"> </span></p>
85 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Answer whether the symbol is a valid primitive name</p>
86 <p class="p6"><span class="Apple-tab-span"> </span></p>
87 <p class="p10"><span class="s8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>'_SymbolIsClassName'<span class="s9">.isPrimitiveName;</span></p>
88 <p class="p6"><br></p>
89 <p class="p6"><br></p>
90 <p class="p11"><b>Conversion</b></p>
91 <p class="p6"><br></p>
92 <p class="p7"><b><span class="Apple-tab-span"> </span>asString</b></p>
93 <p class="p6"><span class="Apple-tab-span"> </span></p>
94 <p class="p7"><span class="Apple-tab-span"> </span>Convert to a <a href="../Collections/String.html"><span class="s2">String</span></a></p>
95 <p class="p6"><span class="Apple-tab-span"> </span></p>
96 <p class="p7"><span class="Apple-tab-span"> </span><b>asInteger</b></p>
97 <p class="p6"><span class="Apple-tab-span"> </span></p>
98 <p class="p7"><span class="Apple-tab-span"> </span>Convert to an <a href="../Math/Integer.html"><span class="s2">Integer</span></a></p>
99 <p class="p6"><span class="Apple-tab-span"> </span></p>
100 <p class="p7"><span class="Apple-tab-span"> </span><b>asClass</b></p>
101 <p class="p6"><span class="Apple-tab-span"> </span></p>
102 <p class="p7"><span class="Apple-tab-span"> </span>Answer the <a href="Kernel/Class.html"><span class="s2">Class</span></a> named by the receiver.</p>
103 <p class="p6"><span class="Apple-tab-span"> </span></p>
104 <p class="p7"><span class="Apple-tab-span"> </span><b>asSetter</b></p>
105 <p class="p6"><span class="Apple-tab-span"> </span></p>
106 <p class="p7"><span class="Apple-tab-span"> </span>Return a symbol with a trailing underscore added.</p>
107 <p class="p6"><span class="Apple-tab-span"> </span></p>
108 <p class="p7"><span class="Apple-tab-span"> </span><b>asGetter</b></p>
109 <p class="p6"><span class="Apple-tab-span"> </span></p>
110 <p class="p7"><span class="Apple-tab-span"> </span>Return a symbol with a trailing underscore removed.</p>
111 <p class="p6"><span class="Apple-tab-span"> </span></p>
112 <p class="p7"><span class="Apple-tab-span"> </span><b>ascii</b></p>
113 <p class="p6"><span class="Apple-tab-span"> </span></p>
114 <p class="p7"><span class="Apple-tab-span"> </span>return the ascii codes as an array</p>
115 <p class="p6"><span class="Apple-tab-span"> </span></p>
116 <p class="p7"><span class="Apple-tab-span"> </span><b>asSpec</b></p>
117 <p class="p6"><span class="Apple-tab-span"> </span></p>
118 <p class="p7"><span class="Apple-tab-span"> </span>Convert to a <a href="../Control/ControlSpec.html"><span class="s2">ControlSpec</span></a></p>
119 <p class="p6"><br></p>
120 <p class="p7"><span class="Apple-tab-span"> </span><b>asTuning</b></p>
121 <p class="p6"><span class="Apple-tab-span"> </span></p>
122 <p class="p7"><span class="Apple-tab-span"> </span>Convert to a <a href="../Collections/Tuning.html"><span class="s2">Tuning</span></a></p>
123 <p class="p6"><span class="Apple-tab-span"> </span></p>
124 <p class="p7"><span class="Apple-tab-span"> </span><b>asScale</b></p>
125 <p class="p6"><span class="Apple-tab-span"> </span></p>
126 <p class="p7"><span class="Apple-tab-span"> </span>Convert to a <a href="../Collections/Scale.html"><span class="s2">Scale</span></a></p>
127 <p class="p6"><span class="Apple-tab-span"> </span></p>
128 <p class="p6"><br></p>
129 <p class="p11"><b>Environments</b></p>
130 <p class="p12"><br></p>
131 <p class="p7">Symbols are used as keys to look up objects in dictionaries and environments, but also in arrays.<span class="Apple-converted-space"> </span></p>
132 <p class="p13"><span class="s9">See <a href="../Collections/IdentityDictionary.html"><span class="s6">IdentityDictionary</span></a>, <a href="../Collections/Environment.html"><span class="s6">Environment</span></a>, <a href="../Collections/Event.html"><span class="s6">Event</span></a></span></p>
133 <p class="p14"><br></p>
134 <p class="p8"><span class="Apple-tab-span"> </span>a = ();</p>
135 <p class="p8"><span class="Apple-tab-span"> </span>a.put(<span class="s4">\commune</span>, 1871);</p>
136 <p class="p15"><span class="s9"><span class="Apple-tab-span"> </span>a.at(</span>\commune<span class="s9">);</span></p>
137 <p class="p6"><br></p>
138 <p class="p7"><span class="Apple-tab-span"> </span><b>envirPut(aValue)</b></p>
139 <p class="p6"><span class="Apple-tab-span"> </span></p>
140 <p class="p7"><span class="Apple-tab-span"> </span>put a value to the current environment using receiver as key</p>
141 <p class="p6"><span class="Apple-tab-span"> </span></p>
142 <p class="p6"><span class="Apple-tab-span"> </span></p>
143 <p class="p7"><span class="Apple-tab-span"> </span><b>envirGet</b></p>
144 <p class="p6"><span class="Apple-tab-span"> </span></p>
145 <p class="p7"><span class="Apple-tab-span"> </span>return a value from the current environment using receiver as key</p>
146 <p class="p6"><span class="Apple-tab-span"> </span></p>
147 <p class="p8"><span class="s6"><span class="Apple-tab-span"> </span></span><span class="s4">\foo</span>.envirPut(100);</p>
148 <p class="p8"><span class="Apple-tab-span"> </span><span class="s4">\foo</span>.envirGet;</p>
149 <p class="p8"><span class="s6"><span class="Apple-tab-span"> </span></span><span class="s4">\foo</span>.envirPut(<span class="s10">nil</span>);</p>
150 <p class="p6"><span class="Apple-tab-span"> </span></p>
151 <p class="p11"><b>Math</b></p>
152 <p class="p6"><br></p>
153 <p class="p7"><span class="Apple-tab-span"> </span>Symbols respond to all unary and binary math operations by returning themselves. The result of any math operation between a Number or other math object and a Symbol is to return the Symbol. This allows for example operations on lists of notes which contain 'rest's to preserve the rests.</p>
154 <p class="p16"><span class="Apple-tab-span"> </span></p>
155 <p class="p8"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s10">Pseq</span>([1, 3, <span class="s4">\rest</span>, 2, 4] + 8);</p>
156 <p class="p6"><span class="Apple-tab-span"> </span></p>
157 <p class="p7"><span class="Apple-tab-span"> </span><b>applyTo(firstArg ... args)</b></p>
158 <p class="p6"><span class="Apple-tab-span"> </span></p>
159 <p class="p7"><span class="Apple-tab-span"> </span>Use the symbol as a method selector and perform the message on <b>firstArg</b>, with <b>args</b> as arguments. This is used for mixing functions with method selectors (see also: <a href="Kernel/Function.html"><span class="s2">Function</span></a>).</p>
160 <p class="p6"><span class="Apple-tab-span"> </span></p>
161 <p class="p8"><span class="s6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s4">'%'</span>.applyTo(2553, 345<span class="s6">);</span></p>
162 <p class="p8"><span class="s6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>[<span class="s4">'+'</span>, <span class="s4">'-'</span>, <span class="s4">'*'</span>, { <span class="s10">|a, b|</span> a.rand + b.rand } ].choose.applyTo(2, 3);</p>
163 <p class="p9"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
164 <p class="p9"><span class="Apple-tab-span"> </span></p>
165 <p class="p6"><span class="Apple-tab-span"> </span></p>
166 <p class="p11"><b>Synthesis</b></p>
167 <p class="p6"><br></p>
168 <p class="p7"><span class="Apple-tab-span"> </span>Inside SynthDefs and UGen functions, symbols can be used to conventiently specify control inputs of different rates and with lags (see:<span class="Apple-converted-space">  </span><a href="../UGens/Synth control/NamedControl.html"><span class="s2">NamedControl</span></a>, <a href="../UGens/Synth control/ControlName.html"><span class="s2">ControlName</span></a><span class="s2">, </span>and<span class="s2"> <a href="../UGens/Synth control/Control.html"><span class="s11">Control</span></a></span>).</p>
169 <p class="p6"><span class="Apple-tab-span"> </span></p>
170 <p class="p6"><span class="Apple-tab-span"> </span></p>
171 <p class="p7"><span class="Apple-tab-span"> </span><b>kr(val, lag)</b></p>
172 <p class="p6"><span class="Apple-tab-span"> </span></p>
173 <p class="p7"><span class="Apple-tab-span"> </span>Return a control rate <a href="../UGens/Synth control/NamedControl.html"><span class="s2">NamedControl</span></a> input with a default value (<b>val</b>), and if supplied, with a <b>lag</b>. If val is an array, the control will be multichannel.</p>
174 <p class="p6"><span class="Apple-tab-span"> </span></p>
175 <p class="p8"><span class="Apple-tab-span"> </span>a = { <span class="s10">SinOsc</span>.ar(<span class="s5">\freq</span>.kr(440, 1.2)) }.play;</p>
176 <p class="p8"><span class="Apple-tab-span"> </span>a.set(<span class="s5">\freq</span>, 330);</p>
177 <p class="p8"><span class="Apple-tab-span"> </span>a.release;</p>
178 <p class="p8"><span class="s6"><span class="Apple-tab-span"> </span></span>a = { <span class="s12">SinOsc</span>.ar(<span class="s5">\freq</span>.kr([440, 460], 1.2)) }.play;</p>
179 <p class="p8"><span class="Apple-tab-span"> </span>a.setn(<span class="s5">\freq</span>, [330, 367]);</p>
180 <p class="p8"><span class="Apple-tab-span"> </span>a.release;</p>
181 <p class="p9"><span class="Apple-tab-span"> </span></p>
182 <p class="p7"><span class="s7"><span class="Apple-tab-span"> </span></span><b>ar(val, lag)</b></p>
183 <p class="p6"><span class="Apple-tab-span"> </span></p>
184 <p class="p7"><span class="Apple-tab-span"> </span>Return an audio rate <a href="../UGens/Synth control/NamedControl.html"><span class="s2">NamedControl</span></a><span class="s2"> </span>input with a default value (<b>val</b>), and if supplied, with a <b>lag</b>. If val is an array, the control will be multichannel.</p>
185 <p class="p12"><br></p>
186 <p class="p7"><span class="Apple-tab-span"> </span><b>ir(val)</b></p>
187 <p class="p6"><span class="Apple-tab-span"> </span></p>
188 <p class="p7"><span class="Apple-tab-span"> </span>Return an intitalization rate <a href="../UGens/Synth control/NamedControl.html"><span class="s2">NamedControl</span></a><span class="s2"> </span>input with a default value (<b>val</b>). If val is an array, the control will be multichannel.</p>
189 <p class="p6"><span class="s7"><span class="Apple-tab-span"> </span></span><span class="Apple-tab-span"> </span></p>
190 <p class="p7"><span class="Apple-tab-span"> </span><b>tr(val)</b></p>
191 <p class="p6"><span class="Apple-tab-span"> </span></p>
192 <p class="p7"><span class="Apple-tab-span"> </span>Return a TrigControl input with a default value (<b>val</b>). If val is an array, the control will be multichannel.</p>
193 <p class="p6"><span class="Apple-tab-span"> </span></p>
194 <p class="p8"><span class="Apple-tab-span"> </span>a = { <span class="s10">Ringz</span>.ar(<span class="s10">T2A</span>.ar(<span class="s5">\trig</span>.tr), <span class="s5">\freq</span>.kr(500, 1), 0.8) }.play;</p>
195 <p class="p8"><span class="Apple-tab-span"> </span>a.set(<span class="s5">\freq</span>, 330, <span class="s5">\trig</span>, 1);</p>
196 <p class="p8"><span class="Apple-tab-span"> </span>a.set(<span class="s5">\freq</span>, 830, <span class="s5">\trig</span>, 1);</p>
197 <p class="p8"><span class="Apple-tab-span"> </span>a.release;</p>
198 <p class="p9"><br></p>
199 <p class="p9"><span class="Apple-tab-span"> </span></p>
200 </body>
201 </html>