Operators
The Alloy configuration syntax uses a standard set of operators. All operations follow the PEMDAS order of mathematical operations.
Arithmetic operators
String operators
Comparison operators
You can use the equality operators ==
and !=
with any operands.
The operands in ordering operators <
, <=
, >
, and >=
must be orderable and of the same type.
The results of these comparisons are:
- Boolean values are equal if both are either
true
orfalse
. - Numerical (integer and floating-point) values are ordered in the usual way.
- String values are ordered lexically, byte-wise.
- Objects are equal if all their fields are equal.
- Arrays are equal if their corresponding elements are equal.
Logical operators
Logical operators work with boolean values and return a boolean result.
Assignment operator
The Alloy configuration syntax uses =
as the assignment operator.
An assignment statement can only assign a single value. Each value must be assignable to the attribute or object key.
- You can assign
null
to any attribute. - You can assign numerical, string, boolean, array, function, capsule, and object types to attributes of the corresponding type.
- You can assign numbers to string attributes with an implicit conversion.
- You can assign strings to numerical attributes if they represent a number.
- You can’t assign blocks.
Brackets
For example, the following code uses curly braces and square brackets to define an object and an array.
obj = { app = "alloy", namespace = "dev" }
arr = [1, true, 7 * (1+1), 3]
Access operators
You can use the Alloy access operators to retrieve nested values. Use square brackets to access zero-indexed array elements or object fields by enclosing the field name in double quotes. Use the dot operator to access object fields without double quotes or component exports.
obj["app"]
arr[1]
obj.app
local.file.token.content
If you use the [ ]
operator to access a non-existent object member, the result is null
.
If you use the .
operator to access a non-existent named member of an object, an error occurs.