...
Operator / Delimiter / Constant | Type | Example | Result of example | Description |
---|---|---|---|---|
null | constant | null + 1 | 1 | Null value, see above |
false | constant | 1 == 0 | false | Integer value 0, useful in Boolean expressions |
true | constant | null == 0 | true | Integer value 1, useful in Boolean expressions |
pi | constant | 2 * pi | 6.2831853rad | π as an angle (same as 180deg) |
() | delimiter | (2 + 4) * (6 + 1) | 42 | Parentheses for arithmetic grouping |
[] | delimiter | [1, 2, 2+1, 'string'] | [1, 2, 3, 'string'] | List of values (see below) |
{} | delimiter | {101, 3} | 'Some text' | Text lookup (page ID and text ID) from TextDB |
+ | unary | +21 * (+2) | 42 | Denotes positive number (no effect) |
- | unary | -(21 * -2) | 42 | Negates the following number |
not | unary | not (21 == 42) | true | Yields true if the following expression is false (equal to zero), false otherwise |
typeof | unary | typeof null typeof 0 typeof 'Hello world' | datatype.null datatype.integer datatype.string | Yields the data type of the following sub-expression |
sin | unary | sin(30deg) sin(pi) | 0.5 1.0 | Sine (function-style, parentheses required) |
cos | unary | cos(60deg) cos(pi) | 0.5 0.0 | Cosine (function-style, parentheses required) |
sqrt | unary | sqrt(2) | 1.414213LF | Square root (function-style, parentheses required) |
exp | unary | exp(1) | 2.71828LF | Exponential function (function-style, parentheses required) |
log | unary | log(8) / log(2) | 3.0LF | Natural logarithm (function-style, parentheses required) |
^ | binary | 10 ^ 3 | 1000.0LF | Power |
* | binary | 21 * 2 | 42 | Multiplication |
/ | binary | 42 / 10 | 4 | Division |
% | binary | 42 % 10 | 2 | Modulus (remainder of integer division) |
+ | binary | 1 + 1 'Hello' + ' world' | 2 'Hello world' | Addition String concatenation |
- | binary | 1 - 1 | 0 | Subtraction |
lt < (<) | binary | 1 lt 3 1 < 3 | true | Less than |
le <= | binary | 1 le 3 1 <= 3 | true | Less than or equal to |
gt > (>) | binary | 1 gt 3 1 > 3 | false | Greater than |
ge >= | binary | 1 ge 3 1 >= 3 | false | Greater than or equal to |
== | binary | 1 + 1 == 2.0 | true | Equal to |
!= | binary | 1 + 1 != 2.0 | false | Not equal to |
and | binary | true and false | false | Logical AND (strict short-circuit semantics) |
or | binary | true or false | true | Logical OR (strict semantics)short-circuit semantics) |
if ... then ... if ... then ... else ... | ternary | if 1 == 2 then 'F' if 1 == 2 then 'F' else 'T' | null 'T' | Conditional operator ("inline if") |
Operator precedence rules
...
Unary operators: +, -, not, typeof, function-style operators (highest precedence)
Power operator: ^
Multiplicative: *, /, %
Additive: +, -
Comparison: lt, le, gt, ge
Equality: ==, !=
and
or
if/then/else (lowest precedence)
Type conversion
...
There is a way to convert a number into a different type manually: You append the corresponding suffix to a sub-expression in parentheses, like this:
(1 + 1)f
⟹2f
⟹2.0
(1h) m / (180deg) i
⟹(3600s) m / (3.14rad) i
⟹3600m / 3
⟹1200m
When converting to a non-default unit type, this means you interpret the number as in the given units: “(1km + 500m)
h” h
” means that you interpret 1500m as 1500 hours, so the resulting value will be 1500x3600 seconds. (As stated above, the default unit for a length is metres.)
...
Every data type can be combined with a string with the + operator, and will be converted to a string representation. That way you can also concatenate strings and numbers:
'One plus one is equal to ' + (1+1) + '.'
⟹'One plus one is equal to 2.'
'One plus one is not equal to ' + 1 + 1 + '.'
⟹'One plus one is not equal to 11.'
As you can see, operators of the same precedence (+ in this case) are always evaluated from left to right.
...
Of course a Boolean operation always results in true or false (integer 1 or 0).
Values of any type can be used as Boolean operands, e.g. for “and”. They will be interpreted as “true” if they are non-zero or non-numeric.
!= and == can be used with any data types, even non-numeric ones. When comparing two numeric values, they are converted using the rules above. Values of non-numeric types are never equal to null, or to any other numbers.
“and” and “or” use strict semantics: Both operands (left and right side expressions) are evaluated and then the result is calculated. This is different from C/C++, in which short-circuit semantics are used and the : The right side expression can be ignored. If you need this, you can simply use nested XML nodes instead of a single expression, e.g. <check_all> and <check_any>.of the operation can be skipped if the left side already determines the outcome of the operation
Example:
false and $foo
⟹false
(the value of $foo is not checked at all)
Unlike != and ==, the comparison operators <, <=, >, >= are only supported for numeric values, difficulty levels, and attention levels. Comparing other non-numeric values will result in an error and an undefined result.
<, <=, >, >= cannot be used in XML directly, so lt, le, gt, ge are provided as alternatives. In some cases you won’t have to use them, though - using range checks with additional XML attributes can be more readable (see below).
...
You can concatenate string literals using the + operator, but there is also a printf-like formatting syntax, which is easier to use than concatenating lots of small pieces:
'The %1 %2 %3 jumps over the %5 %4'.['quick', 'brown', 'fox', 'dog', 'lazy']
'%1 + %2 = %3'.[$a, $b, $a + $b]
See also the section about value properties below.
...