Parentheses (round brackets) have highest precedence. You can use them to override precedence as usual.
You can use square brackets to construct a list. Just add the list
items (which may be lists as well) into square brackets, separated by
commas:
someList = [1, 3, 4, 5, 6, 7, 9]
You can give numeric ranges by using the .. operator:
someList = [1, 3 .. 7, 9]
Variables and literals (which are atomic) have been described elsewhere.
Key literals can be written by writing the name of the key in angle brackets:
key = <NUM+>
They are converted to a number, representing the scancode of the key. Note that there may not be any whitespace in the key literal, to avoid ambiguities with the greater-than and less-than operators.
Next priority are postfix operators.
list[subscript]
list[from..to] # slice
list[<] # empty slice at beginning
list[>] # empty slice at end
Subscripts and slices work like in subscript or slice assignment. Indices start at one, negative indices count from the end of the list. Empty slices are usually used for slice assignment.
Function calls are treated like postfix operators as well.
FunctionName(param1, , param3)
They act like command calls, but return a value. You will find functions in the Insert menu as well.
Prefix operators come next. They have lower priority than postfix operators to make constructs like $list[1] work as expected.
| Prefix | Effect |
|---|---|
| # | Construct a character from a unicode codepoint. For example, #65 is "A". |
| ~ | Constructs a random number from 0 to argument - 1. For example, 1+~6 returns the result of one dice roll. |
| $ | Returns the length of a list or string. |
| ! | Returns a negated condition. This will return 1 if argument is 0 and 0 otherwise. |
| - | Returns a negated number, i. e. 0 - argument |
| % | Returns the level of the datatype of argument. 0 = number, 1 = string, 2 = array, 3 = wrapped object |
Binary operators have different precedence, like in maths:
Highest priority is ^ (exponentiation), next is * and / and % (modulo), next is + and (binary) -, and last are string concatenations & and &&. The latter concatenation adds a newline character between the two strings and comes in handy when building multi-line messages. You can also use the & operator to concatenate lists; this will only work if both arguments are lists. The * operator can be used to multiply a number (first factor) with a list (second factor). This can be useful for pre-filling arrays, like 2*[5*[1]] to create a 2x5 array filled with 1. Negative factor reverts the list before multiplying. Note that this does not work for strings, but you can split, multiply and then join it.
Compare operators have lowest precedence. The operators "=" and "!=" compare strings. The remaining operators "<", ">",, "<=", ">=" and "<>" compare numbers. The result is 1 for true or 0 for false.
Note: When negating comparisons using the ! prefix operator, you have to use parentheses to get the priorities right.