polymorphism: better names for .binaryValue and .booleanValue are .asInteger and...
[supercollider.git] / Help / Language / SymbolicNotations.html
blobb7fc235b18985322014aadc53362915b1b927c2d
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="824.48">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.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: 12.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #007300}
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 0.0px; font: 9.0px Monaco; color: #0000bf}
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; min-height: 12.0px}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
20 span.s1 {color: #000000}
21 span.s2 {font: 12.0px Helvetica}
22 span.s3 {font: 9.0px Monaco}
23 span.s4 {color: #0000bf}
24 span.s5 {color: #606060}
25 span.s6 {color: #0000bf}
26 span.s7 {font: 9.0px Monaco; color: #0000bf}
27 span.s8 {color: #0000bf}
28 span.Apple-tab-span {white-space:pre}
29 </style>
30 </head>
31 <body>
32 <p class="p1"><b>Catalog of symbolic notations in SuperCollider<span class="Apple-converted-space"> </span></b></p>
33 <p class="p2"><br></p>
34 <p class="p3"><b>Arithmetic operators</b></p>
35 <p class="p2"><br></p>
36 <p class="p3">Math operators apply to many classes, including arrays and other collections.</p>
37 <p class="p2"><br></p>
38 <p class="p3">Using a basic math operator on a Symbol swallows the operation (returns the symbol)<span class="Apple-converted-space"> </span></p>
39 <p class="p2"><br></p>
40 <p class="p4">\symbol<span class="s1"> * 5</span></p>
41 <p class="p5">symbol<span class="Apple-converted-space"> </span></p>
42 <p class="p2"><br></p>
43 <p class="p5">number + number<span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>addition</span></p>
44 <p class="p3"><span class="s3">number - number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>subtraction</p>
45 <p class="p3"><span class="s3">number * number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>multiplication</p>
46 <p class="p5">number / number<span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>division</span></p>
47 <p class="p5">number % number<span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>modulo</span></p>
48 <p class="p3"><span class="s3">number ** number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>exponentiation</p>
49 <p class="p2"><br></p>
50 <p class="p2"><br></p>
51 <p class="p3"><b>Bitwise arithmetic</b></p>
52 <p class="p2"><br></p>
53 <p class="p3"><span class="s3">number &amp; number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>bitwise and</p>
54 <p class="p5">number | number<span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>bitwise or</span></p>
55 <p class="p3"><span class="s3">number &lt;&lt; number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>bitwise left shift</p>
56 <p class="p3"><span class="s3">number &gt;&gt; number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>bitwise right shift</p>
57 <p class="p3"><span class="s3">number +&gt;&gt; number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>unsigned bitwise right shift</p>
58 <p class="p2"><br></p>
59 <p class="p2"><br></p>
60 <p class="p3"><b>Logical operators</b></p>
61 <p class="p2"><br></p>
62 <p class="p5">object == object<span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>equivalence</span></p>
63 <p class="p5">object === object<span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>identity</span></p>
64 <p class="p3"><span class="s3">object != object</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>not equal to</p>
65 <p class="p3"><span class="s3">object !== object</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>not identical to</p>
66 <p class="p2"><br></p>
67 <p class="p3">Objects may be equivalent but not identical.</p>
68 <p class="p2"><br></p>
69 <p class="p5">[1, 2, 3] == [1, 2, 3]</p>
70 <p class="p6">true</p>
71 <p class="p5">[1, 2, 3] === [1, 2, 3]</p>
72 <p class="p7"><span class="s4">false</span><span class="s1"><span class="Apple-tab-span"> </span></span>// a and b are two different array instances with the same contents</p>
73 <p class="p8"><br></p>
74 <p class="p5">a = b = [1, 2, 3];</p>
75 <p class="p5">a === b;</p>
76 <p class="p7"><span class="s4">true</span><span class="s1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// a and b are the same array instance</p>
77 <p class="p2"><br></p>
78 <p class="p3"><span class="s3">number &lt; number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>comparison (less than)</p>
79 <p class="p3"><span class="s3">number &lt;= number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>comparison (less than or equal to)</p>
80 <p class="p3"><span class="s3">number &gt; number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>comparison (greater than)</p>
81 <p class="p3"><span class="s3">number &gt;= number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>comparison (greater than or equal to)</p>
82 <p class="p2"><br></p>
83 <p class="p5">Boolean &amp;&amp; Boolean<span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>logical And</span></p>
84 <p class="p5">Boolean || Boolean<span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>logical Or</span></p>
85 <p class="p2"><br></p>
86 <p class="p3">When a function is the second operand, these operators perform short-circuiting (i.e., the function is executed only when its result would influence the result of the operation). This is recommended for speed.</p>
87 <p class="p2"><br></p>
88 <p class="p3">With and: and or: second-argument functions will be inlined. If you use &amp;&amp; or ||, no inlining will be done and performance will be slower.</p>
89 <p class="p2"><br></p>
90 <p class="p5">a = 1;</p>
91 <p class="p8"><br></p>
92 <p class="p5">a == 1 and: { <span class="s5">"second condition"</span>.postln; [<span class="s4">true</span>, <span class="s4">false</span>].choose }</p>
93 <p class="p5">second condition</p>
94 <p class="p6">true</p>
95 <p class="p8"><br></p>
96 <p class="p5">a == 1 or: { <span class="s5">"second condition"</span>.postln; [<span class="s4">true</span>, <span class="s4">false</span>].choose }</p>
97 <p class="p6">true</p>
98 <p class="p8"><br></p>
99 <p class="p5">a != 1 and: { <span class="s5">"second condition"</span>.postln; [<span class="s4">true</span>, <span class="s4">false</span>].choose }</p>
100 <p class="p6">false</p>
101 <p class="p8"><br></p>
102 <p class="p5">a != 1 or: { <span class="s5">"second condition"</span>.postln; [<span class="s4">true</span>, <span class="s4">false</span>].choose }</p>
103 <p class="p5">second condition</p>
104 <p class="p6">true</p>
105 <p class="p2"><br></p>
106 <p class="p3">In this case, the second condition will cause an error if a is nil, because nil does not understand addition. a.notNil is a safeguard to ensure the second condition makes sense.</p>
107 <p class="p2"><br></p>
108 <p class="p5">a = <span class="s4">nil</span>;</p>
109 <p class="p5">a.notNil and: { <span class="s5">"second condition"</span>.postln; (a = a+1) &lt; 5 }</p>
110 <p class="p6">false</p>
111 <p class="p8"><br></p>
112 <p class="p5">a = 10;</p>
113 <p class="p5">a.notNil and: { <span class="s5">"second condition"</span>.postln; (a = a+1) &lt; 5 }</p>
114 <p class="p5">second condition</p>
115 <p class="p6">false</p>
116 <p class="p2"><br></p>
117 <p class="p2"><br></p>
118 <p class="p3"><b>Array and Collection operators</b></p>
119 <p class="p2"><br></p>
120 <p class="p3"><span class="s3">object ++ object</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>concatenation</p>
121 <p class="p3"><span class="s3">collection +++ collection</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>lamination (see <a href="J_concepts_in_SC.html"><span class="s6">J_concepts_in_SC</span></a>)</p>
122 <p class="p2"><br></p>
123 <p class="p3"><span class="s3">collection @ index</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>collection/array indexing: .at(index) or [index]</p>
124 <p class="p3"><span class="s3">collection @@ integer</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>collection/array indexing: .wrapAt(int)</p>
125 <p class="p3"><span class="s3">collection @|@ integer</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>collection/array indexing: .foldAt(int)</p>
126 <p class="p3"><span class="s3">collection |@| integer</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>collection/array indexing: .clipAt(int)</p>
127 <p class="p2"><br></p>
128 <p class="p2"><br></p>
129 <p class="p3"><b>Set operators</b></p>
130 <p class="p2"><br></p>
131 <p class="p3"><span class="s3">set &amp; set</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>intersection of two sets</p>
132 <p class="p3"><span class="s3">set | set</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>union of two sets</p>
133 <p class="p3"><span class="s3">setA - setB</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>difference of sets (elements of setA not found in setB)</p>
134 <p class="p2"><br></p>
135 <p class="p3"><span class="s3">set -- set</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>symmetric difference</p>
136 <p class="p2"><br></p>
137 <p class="p3">(setA -- setB) == ((setA - setB) | (setB - setA))</p>
138 <p class="p2"><br></p>
139 <p class="p5">a = <span class="s4">Set</span>[2, 3, 4, 5, 6, 7];</p>
140 <p class="p5">b = <span class="s4">Set</span>[5, 6, 7, 8, 9];</p>
141 <p class="p8"><br></p>
142 <p class="p5">a - b</p>
143 <p class="p5"><span class="s4">Set</span>[ 2, 4, 3 ]</p>
144 <p class="p8"><br></p>
145 <p class="p5">b - a</p>
146 <p class="p5"><span class="s4">Set</span>[ 8, 9 ]</p>
147 <p class="p8"><br></p>
148 <p class="p5">((a-b) | (b-a))</p>
149 <p class="p5"><span class="s4">Set</span>[ 2, 9, 3, 4, 8 ]</p>
150 <p class="p8"><br></p>
151 <p class="p5">a -- b</p>
152 <p class="p5"><span class="s4">Set</span>[ 2, 9, 3, 4, 8 ]</p>
153 <p class="p2"><br></p>
154 <p class="p2"><br></p>
155 <p class="p3"><b>Geometry operators</b></p>
156 <p class="p2"><br></p>
157 <p class="p3"><span class="s3">number @ number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>x @ y returns Point(x, y)</p>
158 <p class="p3"><span class="s3">point @ point</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Point(left, top) @ Point(right, bottom)</p>
159 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>returns Rect(left, top, right-left, bottom-top)</p>
160 <p class="p3"><span class="s3">ugen @ ugen</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>create a Point with 2 UGens</p>
161 <p class="p2"><br></p>
162 <p class="p3"><span class="s3">rect &amp; rect</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>intersection of two rectangles</p>
163 <p class="p3"><span class="s3">rect | rect</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>union of two rectangles (returns a Rect</p>
164 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>whose boundaries exactly encompass both Rects)</p>
165 <p class="p2"><br></p>
166 <p class="p2"><br></p>
167 <p class="p3"><b>IOStream operators</b></p>
168 <p class="p2"><br></p>
169 <p class="p3"><span class="s3">stream &lt;&lt; object</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>represent the object as a string and add to the stream<span class="Apple-converted-space"> </span></p>
170 <p class="p2"><br></p>
171 <p class="p3">A common usage is with the Post class, to write output to the post window.</p>
172 <p class="p2"><br></p>
173 <p class="p9"><span class="s4">Post</span><span class="s1"> &lt;&lt; </span>"Here is a random number: "<span class="s1"> &lt;&lt; 20.rand &lt;&lt; </span>".\n"<span class="s1">;</span></p>
174 <p class="p5">Here is a random number: 13.</p>
175 <p class="p2"><br></p>
176 <p class="p3"><span class="s3">stream &lt;&lt;* collection</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>add each item of the collection to the stream</p>
177 <p class="p2"><br></p>
178 <p class="p5"><span class="s4">Post</span> &lt;&lt; [0, 1, 2, 3]</p>
179 <p class="p5">[ 0, 1, 2, 3 ]</p>
180 <p class="p8"><br></p>
181 <p class="p5"><span class="s4">Post</span> &lt;&lt;* [0, 1, 2, 3]</p>
182 <p class="p5">0, 1, 2, 3</p>
183 <p class="p2"><br></p>
184 <p class="p3"><span class="s3">stream &lt;&lt;&lt; object</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>add the object's compile string to the stream</p>
185 <p class="p2"><br></p>
186 <p class="p9"><span class="s4">Post</span><span class="s1"> &lt;&lt;&lt; </span>"a string"</p>
187 <p class="p9">"a string"</p>
188 <p class="p2"><br></p>
189 <p class="p3"><span class="s3">stream &lt;&lt;&lt;* collection</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>add each item's compile string to the stream</p>
190 <p class="p2"><br></p>
191 <p class="p2"><br></p>
192 <p class="p3"><b>Conditional execution operators</b></p>
193 <p class="p2"><br></p>
194 <p class="p3"><span class="s3">object ? object</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>nil check (no .value)</p>
195 <p class="p3"><span class="s3">object ?? function</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>nil check (.value, function is inlined)</p>
196 <p class="p2"><br></p>
197 <p class="p3">If the object is nil, the second expression's value will be used; otherwise, it will be the first object.</p>
198 <p class="p2"><br></p>
199 <p class="p5">a = [<span class="s4">nil</span>, 5];</p>
200 <p class="p8"><br></p>
201 <p class="p5">10.do({ (a.choose ? 20.rand).postln });</p>
202 <p class="p5">10.do({ (a.choose ?? { 20.rand }).postln });</p>
203 <p class="p2"><br></p>
204 <p class="p3">?? { } is generally recommended. ? always evaluates the second expression, even if its value will not be used. ?? evaluates the function conditionally (only when needed). If the function defines no variables, the function will be inlined for speed.<span class="Apple-converted-space"> </span></p>
205 <p class="p2"><br></p>
206 <p class="p3">Especially useful when the absence of an object requires a new object to be created. In this example, it's critical that a new SCSlider not be created if the object was already passed in.</p>
207 <p class="p2"><br></p>
208 <p class="p6"><span class="s1">f = { </span>|slider, parent|</p>
209 <p class="p5"><span class="Apple-tab-span"> </span>slider = slider ?? { <span class="s4">SCSlider</span>.new(parent, <span class="s4">Rect</span>(0, 0, 100, 20)) };</p>
210 <p class="p5"><span class="Apple-tab-span"> </span>slider.value_(0);</p>
211 <p class="p5">};</p>
212 <p class="p2"><br></p>
213 <p class="p3">If the first line inside the function instead read <span class="s3">slider = slider ? </span><span class="s7">SCSlider</span><span class="s3">.new(parent, </span><span class="s7">Rect</span><span class="s3">(0, 0, 100, 20));</span>, a new slider would be created even if it is not needed, or used.</p>
214 <p class="p2"><br></p>
215 <p class="p2"><br></p>
216 <p class="p3"><span class="s3">object !? function</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>execute function if object is not nil</p>
217 <p class="p2"><br></p>
218 <p class="p5">a = [10, <span class="s4">nil</span>].choose;</p>
219 <p class="p5">a !? { <span class="s5">"ran func"</span>.postln };</p>
220 <p class="p7">// equivalent of:</p>
221 <p class="p5">if (a.notNil) { <span class="s5">"ran func"</span>.postln };</p>
222 <p class="p2"><br></p>
223 <p class="p3">Used when an operation requires a variable not to be empty.</p>
224 <p class="p2"><br></p>
225 <p class="p5">f = { <span class="s4">|a|</span> a + 5 };</p>
226 <p class="p5">f.value</p>
227 <p class="p7">// error: nil does not understand +</p>
228 <p class="p8"><br></p>
229 <p class="p5">f = { <span class="s4">|a|</span> a !? { a+5 } };</p>
230 <p class="p5">f.value</p>
231 <p class="p7"><span class="s4">nil</span><span class="s1"><span class="Apple-tab-span"> </span></span>// no error</p>
232 <p class="p5">f.value(2)</p>
233 <p class="p5">7</p>
234 <p class="p2"><br></p>
235 <p class="p2"><br></p>
236 <p class="p3"><b>Miscellaneous operators</b></p>
237 <p class="p2"><br></p>
238 <p class="p3"><span class="s3">object ! number</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>object.dup(number)</p>
239 <p class="p2"><br></p>
240 <p class="p5">15 ! 5</p>
241 <p class="p5">[ 15, 15, 15, 15, 15 ]</p>
242 <p class="p2"><br></p>
243 <p class="p3">If the object is a function, it behaves like Array.fill(number, function).</p>
244 <p class="p2"><br></p>
245 <p class="p5">{ 10.rand } ! 5</p>
246 <p class="p5">[ 8, 9, 3, 8, 0 ]</p>
247 <p class="p2"><br></p>
248 <p class="p3"><span class="s3">object -&gt; object</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>creates an Association, used in dictionaries</p>
249 <p class="p2"><br></p>
250 <p class="p3"><span class="s3">expression &lt;! expression</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>bypass value of second expression<span class="Apple-converted-space"> </span></p>
251 <p class="p2"><br></p>
252 <p class="p3">This operator evaluates both expressions, and returns the value of the first.</p>
253 <p class="p2"><br></p>
254 <p class="p5">a = 0;</p>
255 <p class="p5">0</p>
256 <p class="p8"><br></p>
257 <p class="p7">// a is incremented twice, but the return value (1)</p>
258 <p class="p7">// comes from the first increment (0 + 1)</p>
259 <p class="p5">(a = a + 1) &lt;! (a = a + 1)</p>
260 <p class="p5">1</p>
261 <p class="p8"><br></p>
262 <p class="p7"><span class="s1">a<span class="Apple-tab-span"> </span></span>// a's value reflects both increments</p>
263 <p class="p5">2</p>
264 <p class="p2"><br></p>
265 <p class="p3"><span class="s3">function &lt;&gt; function</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>function composition operator<span class="Apple-converted-space"> </span></p>
266 <p class="p2"><br></p>
267 <p class="p3">This operator returns a new function, which evaluates the second function and passes the result to the first function.</p>
268 <p class="p2"><br></p>
269 <p class="p5">f = { <span class="s4">|a|</span> a * 5 } &lt;&gt; {<span class="s4">|a|</span> a + 2 };</p>
270 <p class="p5">f.(10);</p>
271 <p class="p7"><span class="s1">60<span class="Apple-tab-span"> </span></span>// == (10+2) * 5</p>
272 <p class="p2"><br></p>
273 <p class="p3">An array as argument is passed through the chain:</p>
274 <p class="p8"><br></p>
275 <p class="p5">f.([10, 75, 512]);</p>
276 <p class="p7"><span class="s1">[ 60, 385, 2570 ]<span class="Apple-tab-span"> </span></span>// == ([10, 75, 512]+2) * 5</p>
277 <p class="p2"><br></p>
278 <p class="p2"><br></p>
279 <p class="p3"><b>Symbolic notations to define literals/other objects</b></p>
280 <p class="p2"><br></p>
281 <p class="p3"><span class="s3">$</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>character prefix: "ABC".at(0) == $A</p>
282 <p class="p3"><span class="s3">''</span> or <span class="s3">\</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define a literal Symbol: 'abc' === \abc</p>
283 <p class="p3"><span class="s3">""</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define a literal String</p>
284 <p class="p3"><span class="s3">[item, item...]</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define an Array containing given items</p>
285 <p class="p3"><span class="s7">Set</span><span class="s3">[item, item...]</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define a Set -- any Collection class name can be used other than Set</p>
286 <p class="p3"><span class="s3">#[item, item...]</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define a literal Array</p>
287 <p class="p3"><span class="s3">(a:1, b:2)</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define an Event (same as Event[\a -&gt; 1, \b -&gt; 2])</p>
288 <p class="p3"><span class="s3">`</span> (backtick or backquote)<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define a Ref: `1 == Ref(1), `(a+1) == Ref(a+1)</p>
289 <p class="p2"><br></p>
290 <p class="p3"><span class="s3">\</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>inside a string or symbol, escapes the next character</p>
291 <p class="p2"><br></p>
292 <p class="p5">"abc\"def\"ghi"</p>
293 <p class="p5">abc"def"ghi</p>
294 <p class="p8"><br></p>
295 <p class="p5">'abc\'def\'ghi'</p>
296 <p class="p5">abc'def'ghi</p>
297 <p class="p2"><br></p>
298 <p class="p3">\t<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>tab character</p>
299 <p class="p3">\n<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>newline character</p>
300 <p class="p3">\l<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>linefeed character</p>
301 <p class="p3">\r<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>carriage return character</p>
302 <p class="p3">\\<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>\ character</p>
303 <p class="p2"><br></p>
304 <p class="p3"><span class="s3">{ }</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define an open function</p>
305 <p class="p3"><span class="s3">#{ }</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define a closed function</p>
306 <p class="p3"><span class="s3">(_ * 2)</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define a function { |a| a * 2 } (see <a href="Partial-Application.html"><span class="s6">Partial-Application</span></a>)</p>
307 <p class="p2"><br></p>
308 <p class="p3"><b>Argument definition</b></p>
309 <p class="p2"><br></p>
310 <p class="p3"><span class="s3">|a, b, c|</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define function/method arguments</p>
311 <p class="p3"><span class="s3">|a, b ... c|</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define function/method arguments;</p>
312 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>arguments after a and b will be placed into c as an array</p>
313 <p class="p2"><br></p>
314 <p class="p3"><span class="s3">#a, b, c = myArray</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>assign consecutive elements of myArray to multiple variables</p>
315 <p class="p3"><span class="s3">#a, b ... c = myArray</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>assign first two elements to a and b; the rest as an array into c</p>
316 <p class="p2"><br></p>
317 <p class="p3"><b>Where f is a function</b></p>
318 <p class="p2"><br></p>
319 <p class="p3"><span class="s3">f.( )</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>evaluate the function with the arguments in parentheses</p>
320 <p class="p3"><span class="s3">f.(*argList)</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>evaluate the function with the arguments in an array</p>
321 <p class="p3"><span class="s3">f.(anArgName: value)</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>keyword addressing of function or method arguments</p>
322 <p class="p2"><br></p>
323 <p class="p10">f = { <span class="s8">|a, b|</span> a * b };</p>
324 <p class="p10">f.(2, 4);</p>
325 <p class="p10">f.(*[2, 4]);</p>
326 <p class="p10">f.(a: 2, b: 4);</p>
327 <p class="p2"><br></p>
328 <p class="p2"><br></p>
329 <p class="p3"><span class="s7">SomeClass</span><span class="s3">.[index]</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Equivalent to SomeClass.at(index) -- Instr.at is a good example</p>
330 <p class="p2"><br></p>
331 <p class="p3"><span class="s3">myObject.method(*array)</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>call the method with the arguments in an array</p>
332 <p class="p3"><span class="s3">obj1 method: obj2</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>same as obj1.method(obj2) or method(obj1, obj2)</p>
333 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>This works only with single-argument methods</p>
334 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>like binary operators.</p>
335 <p class="p2"><br></p>
336 <p class="p3"><b>Class and instance variable access</b></p>
337 <p class="p2"><br></p>
338 <p class="p3">Inside a class definition (see <a href="../Extending and Customizing SC/Writing-Classes.html"><span class="s6">Writing-Classes</span></a>):</p>
339 <p class="p2"><br></p>
340 <p class="p3"><span class="s7">classvar</span><span class="s3"> &lt;a,</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Define a class variable with a getter method (for outside access)</p>
341 <p class="p3"><span class="s3"><span class="Apple-tab-span"> </span>&gt;b,</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Define a class variable with a setter method</p>
342 <p class="p3"><span class="s3"><span class="Apple-tab-span"> </span>&lt;&gt;c;</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Define a class variable with both a getter and setter method</p>
343 <p class="p2"><br></p>
344 <p class="p3"><span class="s7">var</span><span class="s3"><span class="Apple-tab-span"> </span>&lt;a,</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Define an instance variable with a getter method (for outside access)</p>
345 <p class="p3"><span class="s3"><span class="Apple-tab-span"> </span>&gt;b,</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Define an instance variable with a setter method</p>
346 <p class="p3"><span class="s3"><span class="Apple-tab-span"> </span>&lt;&gt;c;</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Define an instance variable with both a getter and setter method</p>
347 <p class="p2"><br></p>
348 <p class="p3">These notations do not apply to variables defined within methods.</p>
349 <p class="p2"><br></p>
350 <p class="p3"><span class="s3">^someExpression</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Inside a method definition: return the expression's value to the caller</p>
351 <p class="p2"><br></p>
352 <p class="p3"><span class="s3">instVar_ { }</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>define a setter for an instance variable</p>
353 <p class="p3"><span class="s3">myObject.instVar = x;</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>invoke the setter: (myObject.instVar_(x); x)</p>
354 <p class="p2"><br></p>
355 <p class="p3"><b>Array series and indexing</b></p>
356 <p class="p2"><br></p>
357 <p class="p3"><span class="s3">(a..b)</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>produces an array consisting of consecutive integers from a to b</p>
358 <p class="p3"><span class="s3">(a, b..c)</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>e.g.: (1, 3..9) produces [1, 3, 5, 7, 9]</p>
359 <p class="p3"><span class="s3">(..b)</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>produces an array 0 through b</p>
360 <p class="p3"><span class="s3">(a..)</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>not legal (no endpoint given)</p>
361 <p class="p2"><br></p>
362 <p class="p3"><span class="s3">a[i..j]</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a.copyRange(i, j)</p>
363 <p class="p3"><span class="s3">a[i, j..k]</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>e.g.: a[1, 3..9] retrieves array elements 1, 3, 5, 7, 9</p>
364 <p class="p3"><span class="s3">a[..j]</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a.copyRange(0, j)</p>
365 <p class="p3"><span class="s3">a[j..]</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a.copyRange(i, a.size-1)<span class="Apple-converted-space">  </span>(this is OK--Array is finite)</p>
366 <p class="p2"><br></p>
367 <p class="p3"><span class="s3">~</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>access an environment variable</p>
368 <p class="p3"><span class="s3">~abc</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>compiles to \abc.envirGet</p>
369 <p class="p3"><span class="s3">~abc = value</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>compiles to \abc.envirPut(value)</p>
370 <p class="p2"><br></p>
371 <p class="p3"><b>Adverbs to math operators</b> (see <a href="Adverbs.html"><span class="s6">Adverbs</span></a>)</p>
372 <p class="p2"><br></p>
373 <p class="p3">e.g.:</p>
374 <p class="p5">[1, 2, 3] * [2, 3, 4]</p>
375 <p class="p5">[ 2, 6, 12 ]</p>
376 <p class="p8"><br></p>
377 <p class="p5">[1, 2, 3] *.t [2, 3, 4]</p>
378 <p class="p5">[ [ 2, 3, 4 ], [ 4, 6, 8 ], [ 6, 9, 12 ] ]</p>
379 <p class="p2"><br></p>
380 <p class="p3"><span class="s3">.s</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>output length is the shorter of the two arrays</p>
381 <p class="p3"><span class="s3">.f</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>use folded indexing instead of wrapped indexing</p>
382 <p class="p3"><span class="s3">.t</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>table-style</p>
383 <p class="p3"><span class="s3">.x</span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>cross (like table, except that the results of each operation</p>
384 <p class="p3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>are concatenated, not added as another dimension)</p>
385 <p class="p2"><br></p>
386 <p class="p3"><span class="s3">.0<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>operator depth (see <a href="J_concepts_in_SC.html"><span class="s6">J_concepts_in_SC</span></a>)</p>
387 <p class="p3"><span class="s3">.1</span> etc.</p>
388 </body>
389 </html>