Skip to main content

Operators

The following are the set of built-in unary, binary and conditional operators

Unary operators

The operator not provides the boolean negation, e.g. not true is false.

The operator - provides the negative of a number, e.g. -(-1) is 1.

Binary operators

The binary operators are:

  • + is the addition operator for numbers. It can also be used to concatenate strings.

  • - is the subtraction operator for numbers.

  • * is the mutiplication operator for numbers.

  • / is the division operator for numbers. It can return an error when dividing a number by zero.

  • % is the mod operator for numbers.

  • == is the equality operator and can be used for numbers, strings, and temporal types, e.g. 2 == 2 is true.

  • <= is the less or equal to operator and can be used for numbers, strings, and temporal types.

  • < is the less operator and can be used for numbers, strings, and temporal types.

  • >= is the greater or equal to operator and can be used for numbers, strings, and temporal types.

  • > is the greater operator and can be used for numbers, strings, and temporal types.

Strings are compared lexicographically.

Temporal types must be of the same type: e.g. a date can only be compared to another date type, and not to a time or timestamp type.

  • and is the logical and boolean operator, e.g. true and false is false.
  • or is the logical or boolean operator, e.g. true or false is true.

Conditional operators

To check for a condition use if <condition> then <exp1> else <exp2>.

For example:

if (true) then "1" else "2"

Note that both the expressions in then and in else must be of the two compatible types. For instance

if (true) then 1 else 2f

The following is an expression of type float: even though then is 1 which has type int, the else is 2f which has type float. Since an int can be upcasted to a float, then the result type is float.