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