Expressions

Expressions

This chapter describes expressions in Rue.

An expression is a syntactic construct that evaluates to a value.

Every expression has a type.

Evaluation

When an expression contains subexpressions, those subexpressions are evaluated in a defined order as specified in this section.

For binary operators, the left operand is evaluated before the right operand.

For function call expressions, the callee expression is evaluated first, then arguments are evaluated left-to-right.

For index expressions of the form base[index], the base expression is evaluated before the index expression.

For field access expressions of the form base.field, the base expression is evaluated before the field is accessed.

Logical operators && and || are an exception to the normal left-to-right evaluation. They use short-circuit evaluation as specified in section 4.4: the right operand may not be evaluated depending on the value of the left operand.

For struct literal expressions of the form Type { field1: expr1, field2: expr2, ... }, the field initializer expressions are evaluated in source order (left-to-right as written).

In this section