Operators Reference

Special Operators

= (equality)

Application:
infix
Type:
(T?, T) => boolean

Tests for equality, e.g. 5 = 4 yields false while "s" = "s" yields true.

For types tuple and array, the comparison is performed element-wise.

Syntax bug! Due to a bug, the type of the second operand must be assignment compatible to the type of the first operand.
I.e., doing 5.3 = 5 is valid but 5 = 5.3 raises a syntax error. This will be fixed in the future.

!= (inequality)

Application:
infix
Type:
(T?, T) => boolean

Performs the negated operation of = (equality).

Syntax bug! This operator currently suffers from the same bug as = (equality).

if-then-else (ternary)

Application:
special
Type:
(boolean, T?, T) => T

Evaluates the condition (first operand) and if it is true returns the second operand, otherwise returns the third operand.

Examples

Syntax bug! This operator currently suffers from the same bug as = (equality).

asset

Application:
function
Type:
(text) => text

Returns the address of a game asset by using the asset resolver component.

For example, calling asset("star.png") might return something like "https://game-server.org/game-assets/MySpaceGame/star.png".

Check the assets documentation to find out more.


Text Operators

+ (concat text)

Application:
infix
Type:
(text, text) => text

Performs text (string) concatenation, e.g. "alpha" + "bet" yields "alphabet".

toText (integer)

Application:
function
Type:
(int) => text

Converts an integer to text, e.g. toText(5) yields "5".

toText (real)

Application:
function
Type:
(real) => text

Converts a real to text, e.g. toText(5.3) yields "5.3".

toText (boolean)

Application:
function
Type:
(boolean) => text

Converts a boolean to text, e.g. toText(false) yields "false".


Sequence Operators

exists

Application:
prefix
Type:
(seq[?]) => boolean

Returns true iff the sequence is not empty.

Example

count

Application:
prefix
Type:
(seq[?]) => int

Counts the number of elements in the sequence.

Example

first

Application:
prefix
Type:
(seq[E?]) => E

Returns the first element of the sequence or nothing if the sequence is empty.

second

Application:
prefix
Type:
(seq[E?]) => E

Returns the second element of the sequence or nothing if the sequence has fewer than two elements.

third

Application:
prefix
Type:
(seq[E?]) => E

Returns the third element of the sequence or nothing if the sequence has fewer than three elements.

in

Application:
infix
Type:
(E, seq[E?]) => boolean

Returns true iff the element is contained in the sequence.

The elements are compared using the equality operator.

Examples

collect

Application:
prefix
Type:
(seq[E?]) => array[E]

Collects the elements of the sequence into an array.

This is particularly useful for either stabilizing the results of a query or optimizing the performance of lazy operations.

Examples

+ (concat sequence)

Application:
infix
Type:
(seq[E?], seq[E]) => seq[E]

Concatenates the two sequences.

Example

>> (append)

Application:
infix
Type:
(seq[E?], E) => seq[E]

Appends the element to the sequence.

Example

<< (prepend)

Application:
infix
Type:
(E, seq[E?]) => seq[E]

Prepends the element to the sequence.

Example

.. | range

Application:
infix | function
Type:
(int, int) => seq[int]

Returns an integer range from the first operand to the second operand (inclusive).

This operator has two alternative equivalent syntaxes:

  1. The .., eg, 1..3
  2. The function range, eg, range(1, 3)

Examples

cross

Application:
infix
Type:
(seq[X?], seq[Y?]) => seq[(X, Y)]

Calculates the cartesian product of the two sequences.

Example

map

Application:
infix
Type:
(seq[S?], (S) => T?) => seq[T]

Applies the function to the elements of the input sequence and produces the output sequence.

Examples

find

Application:
infix
Type:
(seq[E?], (E) => boolean) => E

Returns the first element for which the function returns true or nothing if there is no such element.

Examples

reduce

Application:
infix
Type:
(seq[E?], Acc, (Acc?, E) => Acc) => Acc

Performs the reduce operation on the sequence.

Examples


Logical Operators

and

Application:
infix
Type:
(boolean, boolean) => boolean

Performs logical conjunction.

or

Application:
infix
Type:
(boolean, boolean) => boolean

Performs logical disjunction.

not

Application:
prefix
Type:
(boolean) => boolean

Performs logical negation.


Arithmetic Operators

+ (integer)

Application:
infix
Type:
(int, int) => int

Adds two integers.

+ (real)

Application:
infix
Type:
(real, real) => real

Adds two reals.

- (integer)

Application:
infix
Type:
(int, int) => int

Subtracts two integers.

- (real)

Application:
infix
Type:
(real, real) => real

Subtracts two reals.

* (integer)

Application:
infix
Type:
(int, int) => int

Multiples two integers.

* (real)

Application:
infix
Type:
(real, real) => real

Multiples two reals.

// (integer division)

Application:
infix
Type:
(int, int) => int

Performs integer division on two integers.

/ (real)

Application:
infix
Type:
(real, real) => real

Divides two reals.

Note: If this operator is used on integers, they will be converted to real. E.g. 5 / 2 will yield 2.5.

% (modulo)

Application:
infix
Type:
(int, int) => int

Returns the modulo of two integers.

- (negate integer)

Application:
prefix
Type:
(int) => int

Negates the given int, e.g. -5.

- (negate real)

Application:
prefix
Type:
(real) => real

Negates the given real, e.g. -5.3.

mathFloor

Application:
function
Type:
(real) => int

Returns the floor of a real, e.g. mathFloor(2.5) yields 2.

mathCeil

Application:
function
Type:
(real) => int

Returns the ceil of a real, e.g. mathFloor(2.5) yields 3.

mathRound

Application:
function
Type:
(real) => int

Rounds a real to the nearest integer.

mathSgn (integer)

Application:
function
Type:
(int) => int

Returns the sign of an int number, that is:

  • if number < 0: return -1
  • if number = 0: return 0
  • if number > 0: return 1

mathSgn (real)

Application:
function
Type:
(real) => int

Returns the sign of a real number, that is:

  • if number < 0: return -1
  • if number = 0: return 0
  • if number > 0: return 1

mathAbs (integer)

Application:
function
Type:
(int) => int

Returns the absolute of an int.

mathAbs (real)

Application:
function
Type:
(real) => real

Returns the absolute of a real.


Arithmetic Comparison Operators

> (integer)

Application:
infix
Type:
(int, int) => boolean

Performs strict integer comparison.

> (real)

Application:
infix
Type:
(real, real) => boolean

Performs strict real comparison.

>= (integer)

Application:
infix
Type:
(int, int) => boolean

Performs non-strict integer comparison.

>= (real)

Application:
infix
Type:
(real, real) => boolean

Performs non-strict real comparison.

< (integer)

Application:
infix
Type:
(int, int) => boolean

Performs strict integer comparison.

< (real)

Application:
infix
Type:
(real, real) => boolean

Performs strict real comparison.

<= (integer)

Application:
infix
Type:
(int, int) => boolean

Performs non-strict integer comparison.

<= (real)

Application:
infix
Type:
(real, real) => boolean

Performs non-strict real comparison.