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)
number + numbernumber - numbernumber * numbernumber / numbernumber % numbernumber ** numbernumber & numbernumber | numbernumber << numbernumber >> numbernumber +>> numberobject == objectobject === objectobject != objectobject !== objectObjects may be equivalent but not identical.
number < numbernumber <= numbernumber > numbernumber >= numberboolean && booleanboolean || booleanWhen 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 and: and or: second-argument functions will be inlined. If you use && or ||, no inlining will be done and performance will be slower.
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.
Operators oftwn used with Array, Collection, List and so on. Due to Polymorphism, the calculation result may vary depending on the class.
object ++ objectcollection +++ collectioncollection @ indexcollection @@ integercollection @|@ integercollection |@| integerset & setset | setsetA - setBset -- setnumber @ numberpoint @ pointugen @ ugenrect & rectrect | rectstream << objectstream <<* collectionstream <<< objectstream <<<* collectionobject ? objectobject ?? function?? { } 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.
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.
If the first line inside the function instead read
, a new slider would be created even if it is not needed, or used.
object !? functionUsed when an operation requires a variable not to be empty.
object ! numberobject.dup(number)If the object is a function, it behaves like Array.fill(number, function).
object -> objectexpression <! expressionfunction <> functionAn array as argument is passed through the chain:
$"ABC".at(0) == $A'' or \'abc' === \abc"""SuperCollider is the best"[item, item...]Set[item, item...]#[item, item...](a:1, b:2)Event[\a -> 1, \b -> 2])` (backtick or backquote)`1 == Ref(1), `(a+1) == Ref(a+1)\\t\n\l\r\\{ }#{ }(_ * 2){ |a| a * 2 } (see Partial Application)|a, b, c||a, b ... c|#a, b, c = myArray#a, b ... c = myArrayf.( )f.(*argList)f.(anArgName: value)SomeClass.[index]myObject.method(*array)obj1 method: obj2obj1.method(obj2) or method(obj1, obj2). This works only with single-argument methods like binary operators.Inside a class definition (see Writing Classes ):
These notations do not apply to variables defined within methods.
^someExpressioninstVar_ { }myObject.instVar = x;(myObject.instVar_(x); x)(a..b)(a, b..c)(..b)(a..)a[i..j]a.copySeries(i, j) (see ArrayedCollection: -copySeries)a[i, j..k]a[1, 3..9] retrieves array elements 1, 3, 5, 7, 9a[..j]a.copySeries(0, j)a[j..]a.copySeries(i, a.size-1) (this is OK--Array is finite)~~abc\abc.envirGet~abc = value\abc.envirPut(value)(see Adverbs for Binary Operators )
e.g.:
.s.f.t.x.0.1