Skip to main content

Operators

Member access

  • Use the dot . to access members of objects: user.name, s.sub(5, 10)

Function call

  • Enclose arguments in parentheses (): print('Hello'), value.to_text()

Element access

  • Use square brackets [] to access elements by index: values[i]

Arithmetic operators

Arithmetic operators operate on numerical values, which can be either literals or variables, and they yield a single numerical result.

OperatorDescription
+The addition (+) operator produces the sum of numeric operands or string concatenation.
-The subtraction (-) operator subtracts the two operands, producing their difference.
*The multiplication (*) operator produces the product of the operands.
/The division (/) operator produces the quotient of its operands where the left operand is the dividend and the right operand is the divisor.
%The modulus (%) operator returns the remainder of two numbers.
++The increment (++) operator increments (adds one to) its operand and returns the value before or after the increment.
--The decrement (--) operator decrements (subtracts one from) its operand and returns the value before or after the decrement.

Relational operators

A comparison operator evaluates its operands and produces a Boolean value that indicates whether the comparison is true.

OperatorDescription
<The less than (<) operator returns true if the left operand is less than the right operand, and false otherwise.
>The greater than (>) operator returns true if the left operand is greater than the right operand, and false otherwise.
<=The less than or equal (<=) operator returns true if the left operand is less than or equal to the right operand, and false otherwise.
>=The greater than or equal (>=) operator returns true if the left operand is greater than or equal to the right operand, and false otherwise.
inThe in operator determines whether an element is present in a specified collection, such as a range, set, map, or any iterable data structure. It returns True if the element is found in the collection and False otherwise. While it is often used to verify the existence of an element within a collection, it is not primarily used for checking object properties.
not inThe not in operator determines whether an element is not present in a specified collection, such as a range, set, map, or any iterable data structure. It returns True if the element is not found in the collection and False otherwise.

Equality operators

The outcome of assessing an equality operator is consistently in the Boolean data type, determined by the truth or falsity of the comparison.

OperatorDescription
==The equality (==) operator checks whether its two operands are equal, returning a Boolean result.
!=The inequality (!=) operator checks whether its two operands are not equal, returning a Boolean result.
===The strict equality (===) operator checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.
!==The strict inequality (!==) operator checks whether its two operands are not equal, returning a Boolean result. Unlike the inequality operator, the strict inequality operator always considers operands of different types to be different.

Operators == and != compare values. For complex types (collections, tuples, structs), they recursively compare member values, and for entity values, they compare object IDs.

Operators === and !== compare references, not values. Use them with types: tuple, struct, list, set, map, GTV, and range.

Example:

val x = [1, 2, 3]
val y = list(x)
print(x == y) // true - values are equal
print(x === y) // false - two different objects

Logical operators

Logical operators can be defined as a type of operators that help us to combine multiple conditional statements. There are three types of logical operators in Rell: AND, OR and NOT operators.

OperatorDescription
andThe logical and operator returns true when both conditions under evaluation are true, otherwise it returns false.
orThe logical or operator returns true if any one of the given conditions is true. It returns false if both conditions under evaluation are false.
notThe logical not operator accepts a single value as an input and returns the inverse of the same. This is a unary operator unlike the and and or operators.

Assignment operators

An assignment operator sets the value of its left operand according to the value of its right operand. It's translated to an update statement.

OperatorDescription
=The assignment (=) operator assigns a value to a variable. The assignment operation evaluates to the assigned value.
*=The multiplication assignment (*=) operator performs multiplication on the two operands and assigns the result to the left operand.
/=The division assignment (/=) operator performs division on the two operands and assigns the result to the left operand.
%=The remainder assignment (%=) operator performs remainder on the two operands and assigns the result to the left operand.
+=The addition assignment (+=) operator performs addition on the two operands and assigns the result to the left operand.
-=The subtraction assignment (-=) operator performs subtraction on the two operands and assigns the result to the left operand.

Example:

You can specify an arbitrary expression returning a entity, a nullable entity, or a collection of entities:

val u = user @? { .name == 'Bob' };
update u ( salary += 5000 );

You can modify a single attribute by a regular assignment syntax:

val u = user @ { .name == 'Bob' };
u.salary += 5000;

At operator

Use the at @ operator for retrieving objects. For more information see, At-operator.

If operator

Use the if operator for conditional evaluation.

variable = IF expression THEN expression ELSE expression

Example:

val max = if (a >= b) a else b
return max