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 + number
number - number
number * number
number / number
number % number
number ** number
number & number
number | number
number << number
number >> number
number +>> number
object == object
object === object
object != object
object !== object
Objects may be equivalent but not identical.
number < number
number <= number
number > number
number >= number
boolean && boolean
boolean || boolean
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 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.
object ++ object
collection +++ collection
collection @ index
collection @@ integer
collection @|@ integer
collection |@| integer
set & set
set | set
setA - setB
set -- set
number @ number
point @ point
ugen @ ugen
rect & rect
rect | rect
stream << object
stream <<* collection
stream <<< object
stream <<<* collection
object ? object
object ?? 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 !? function
Used when an operation requires a variable not to be empty.
object ! number
object.dup(number)
If the object is a function, it behaves like Array.fill(number, function).
object -> object
expression <! expression
function <> function
An 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 = myArray
f.( )
f.(*argList)
f.(anArgName: value)
SomeClass.[index]
myObject.method(*array)
obj1 method: obj2
obj1.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.
^someExpression
instVar_ { }
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