Skip to main content

Expressions

Expressions compute values. They appear in property bodies, on the right-hand side of assignments, in operation guards, in feature multiplicities, and in feature bindings.

Literals​

KindExample
Booleantrue, false
Integer42, -1
Real3.14, 1e-3
String"hello"
Nothingnothing
Infinity*
Array[a, b, c], []
RecordPoint { x = 0, y = 0 }

See Datatypes for the corresponding types.

self​

Inside a class body, self refers to the current class or feature instance.

class Counter {
refers display: Display

redefine init {
inline display.bind(self)
}
}

Operator Precedence​

From lowest to highest precedence:

LevelCategoryOperators
1Temporal (top of expression only)AG, EF
1Boolean&&, ||, ^^
2Comparison<, <=, >, >=, ==, !=
3Range.., ..<
4Additive+, -
5Multiplicative*, /
6Unary!, unary +, unary -
7Postfix / member., ?., [ ], ( )

The boolean operators &&, ||, and ^^ share one precedence level and are left-associative: a && b || c parses as (a && b) || c.

Boolean Operators​

OperatorDescription
&&Logical AND
||Logical OR
^^Logical XOR
!Unary NOT

Comparison Operators​

OperatorDescription
<Less than
<=Less than or equal
>Greater than
>=Greater than or equal
==Equal
!=Not equal

Arithmetic Operators​

OperatorDescription
+Addition (binary) or unary plus
-Subtraction (binary) or unary minus
*Multiplication
/Division

Ranges​

SyntaxDescription
a..bInclusive range from a to b
a..<bExclusive range from a to b-1

Member Access (.)​

The . operator names a member of an instance.

counter.value

Optional Member Access (?.)​

?. navigates through an optional ([0..1]) reference. If the receiver is nothing, the entire expression evaluates to nothing.

parent?.value

Indexing ([])​

Accesses an array element by index.

items[0]

Property Invocation (())​

A property is invoked using the () invocation expression.

prop atLimit(): bool {
return value == maximum()
}

prop pairAtLimit(): bool {
return a.atLimit() && b.atLimit()
}

Temporal Operators​

Temporal operators denote logical formulae over the possible executions of the system.

OperatorMeaning
AG exprAlways globally. expr holds in every reachable state. Use for safety properties.
EF exprExists finally. expr holds in some reachable state. Use for reachability checks.
prop {
return AG counter.value < 100
}
note

Additional temporal operators will be supported in the future.