Operations are the basis for performing calculations, logic, and data processing in the bot's expression language. They allow you to add numbers, check conditions, manipulate strings, work with collections, and much more.
Priority determines the order in which operations are performed. Operations with higher priority are performed first. To explicitly specify the order of execution, use parentheses.
Table of operation priorities:
| Operation | Priority | Associativity | Description |
|---|---|---|---|
** |
12 | Right | Exponentiation |
+, - (unary) |
11 | – | Unary plus and minus |
~ |
11 | – | Bitwise inversion |
! |
10 | – | Logical negation |
*, /, \, % |
9 | Left | Multiplication, division, remainder |
+, - |
8 | Left | Addition, subtraction |
:: |
8 | Left | String concatenation |
<, <=, >, >= |
7 | – | Comparisons |
==, != |
6 | – | Equality, inequality |
& |
5 | Left | Bitwise AND |
^ |
4 | Left | Bitwise exclusive OR |
| |
3 | Left | Bitwise OR |
&& |
2 | Left | Logical AND |
|| |
1 | Left | Logical OR |
Assignment (= etc.) |
0 | Right | Assignment operations |
Arithmetic operations are performed on numbers. If one of the operands is not a number, the interpreter will attempt to convert it to a number.
| Operation | Description | Example |
|---|---|---|
+$a |
Conversion to a number | $a = +“5” |
-$a |
Change sign | $a = -5 |
$a + $b |
Addition | $c = $a + $b |
$a - $b |
Subtraction | $c = $a - $b |
$a * $b |
Multiplication | $c = $a * $b |
$a / $b |
Division | $c = $a / $b |
$a \ $b |
Integer division | $c = $a \ $b |
$a % $b |
Modulo | $c = $a % $b |
$a ** $b |
Exponentiation | $c = $a ** $b |
Logical operations work with Boolean values. If an operand is not Boolean, it will be converted.
| Operation | Description | Example |
|---|---|---|
!$a |
Logical NOT | $b = !$a |
$a && $b |
Logical AND | $c = $a && $b |
$a || $b |
Logical OR | $c = $a \| $b |
Table of conversions to Boolean values:
| Type | Value | Boolean value |
|---|---|---|
nil |
nil |
false |
| Number | 0 |
false |
| Number | Non-zero | true |
| String | Empty | false |
| String | Non-empty | true |
| Object | Any | true |
Bitwise operations work with bit representations of numbers.
| Operation | Description | Example |
|---|---|---|
~$a |
Bitwise inversion | $b = ~$a |
$a & $b |
Bitwise AND | $c = $a & $b |
$a | $b |
Bitwise OR | $c = $a \| $b |
$a ^ $b |
Exclusive OR | $c = $a ^ $b |
Strings can be concatenated using the concatenation operator ::.
| Operation | Description | Example |
|---|---|---|
“a” :: “b” |
String concatenation | “a” :: ‘b’ == “ab” |
Converting other data types to strings:
| Type | Value | String representation |
|---|---|---|
nil |
nil |
“” |
| Number | 123.45 |
“123.45” |
| Boolean | true |
“true” |
| Boolean | false |
“false” |
| Object | Any | Serialization |
Comparisons are performed on any data type, returning Boolean values.
| Operation | Description | Example |
|---|---|---|
$a == $b |
Equality | $a == $b |
$a != $b |
Inequality | $a != $b |
$a > $b |
Greater than | $a > $b |
$a >= $b |
Greater than or equal to | $a >= $b |
$a < $b |
Less than | $a < $b |
$a <= $b |
Less than or equal to | $a <= $b |
Collections support the union operation.
| Operation | Description | Example |
|---|---|---|
(1, 2) + (3, 4) |
Union of tuples | (1, 2, 3, 4) |
[‘a’] + [‘b’] |
Union of lists | [‘a’, ‘b’] |
{‘a’: 0} + {‘b’: 1} |
Union of dictionaries | {‘a’: 0, ‘b’: 1} |
Assignment allows you to set the value of a variable. Combined operations are also available, such as addition with assignment.
| Operation | Description | Example |
|---|---|---|
$a = 123 |
Assignment | $a = 123 |
$a += 1 |
Addition with assignment | $a = $a + 1 |
$a -= 1 |
Subtraction with assignment | $a = $a - 1 |
$a *= 2 |
Multiplication with assignment | $a = $a * 2 |
Example of multiple assignment:
// Assign values to multiple variables
($x, $y, $z) = (1, 2, 3)