A symbol, like a String, is a sequence of characters. Unlike strings, two symbols with exactly the same characters will be the exact same object. Symbols are optimized for recreating the same symbol over and over again. In practice, this means that symbols are best used for identifiers or tags that are only meaningful within your program, whereas you should use a string when your characters are really processed as text data. Use symbols to name things, use strings for input and output.
Good uses of symbols include symbolic constant values and Dictionary keys.
Symbols are represented syntactically as literals which are described in Literals: Symbols.
A symbol can be written by surrounding characters by single quotes (may include whitespace):
'foo bar'
Or by a preceding backslash (then it may not include whitespace):
\foo
A String can be converted into a symbol:
"arbeit".scramble.asSymbol;
Answer whether the symbol can be a class name. This does not say if the class exists.
Answer whether the symbol can be meta class name. This does not say if the class exists.
Answer whether the symbol has a trailing underscore.
Answer whether the symbol is a valid primitive name
Answer whether the symbol is a prefix of another one
Return true if the symbol is a valid variable name, or equivalently a valid method name in the two most common method call syntaxes (foo.bar()
and bar(foo)
). A valid identifier contains only alphanumeric characters and underscores, and the first character must be a lowercase letter.
Return true if the symbol is a valid binary operator. A valid binary operator contains only the symbols !@%&*-+=|<>?/
, does not start with '//
' or '/*
', and is not the string '=
'.
Convert to a String
Convert to an Integer
Answer the Class named by the receiver.
Return a symbol with a trailing underscore added.
Return a symbol with a trailing underscore removed.
return the ascii codes as an array
Convert to a ControlSpec
Convert to a Tuning
Convert to a Scale
Symbols are used as keys to look up objects in dictionaries and environments, but also in arrays. See IdentityDictionary, Environment, Event
put a value to the current environment using receiver as key
return a value from the current environment using receiver as key
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.
Pseq([1, 3, \rest, 2, 4] + 8);
Use the symbol as a method selector and perform the message on firstArg, with args as arguments. This is used for mixing functions with method selectors (see also: Function).
Inside SynthDefs and UGen functions, symbols can be used to conveniently specify control inputs of different rates and with lags (see: NamedControl, ControlName, and Control).
Return a control rate NamedControl input with a default value (val), and if supplied, with a lag. If val is an array, the control will be multichannel. A ControlSpec provided to the spec
parameter will be written into the spec metadata for the current synth.
Return an audio rate NamedControl input with a default value (val), and if supplied, with a lag. If val is an array, the control will be multichannel.
Return an initialization rate NamedControl input with a default value (val). If val is an array, the control will be multichannel.
Return a TrigControl input with a default value (val). If val is an array, the control will be multichannel.