Operators
Below is a list of all of Sparkle's operators, in order of precedence.
The order of precedence is important to understand how expressions are evaluated. Parentheses can be used to change the order of evaluation.
let x be 42
let expression_a be type of x is equal to Integer
let expression_b be type of (x is equal to Integer)
print expression_a # true
print expression_b # BooleanSome of the operators have alternate aliases, for example a plus b and a + b are equivalent.
Returns the negative of the number.
minus a-aErrors:
- The operand is not a number.
Returns the value of the property.
a's bErrors:
- The property doesn't exist.
Calls a function, optionally with parameters.
[do] a [with ___]a [___]Errors:
- The number of parameters doesn't match with the function definition.
- Parameters
by referencemismatch.
For lists and strings, returns the element at the index. For objects, returns the value of the property with the given name.
a at bErrors:
- Index is out of bounds (list/string).
- Property doesn't exist (object).
Returns the result of the operation. Multiplication, division, and modulo take precedence over addition, subtraction, and exponentiation.
a times b
a divided by b
a divided whole by b
a modulo b
a plus b
a minus b
a raised to ba * b
a / b
a // b
a % b
a + b
a - b
a ^ bErrors:
- Invalid operand type.
- Dividing by zero.
Returns the class of the value.
type of aReturns true if the value b exists in the iterator of a.
a has bErrors:
- Invalid operand type,
ais not an Iterable.
Note:
- If
ais an infinite iterable andbnever appears, this operation will never terminate.
Returns a boolean comparison of two values.
a is greater than b
a is less than b
a is greater or equal to b
a is less or equal to ba > b
a < b
a >= b
a <= bErrors:
- Operand types mismatch.
Checks the equality of two values. For lists and objects, performs a deep equality check.
For functions, returns true if they reference the same function.
If the operands are not of the same type, returns false.
a is equal to b
a is not equal to ba = b
a != bReturns the result of a logical operation between two boolean values.
a and b
a or b
not aErrors:
- Operand not a boolean.
User defined classes may overload the unary minus, arithmetic, comparison, equality, and boolean operators, but they retain their order of precedence.
print "hello world"