BRAIDGROUP
RESEARCH & DEV
48. Documentation

Operator Reference

Complete operator reference in precedence order (highest to lowest).

Operator Precedence Table

PrecedenceOperatorsDescriptionAssociativity
1 (highest)() [] .Grouping, function call, member access, array/tensor indexingLeft-to-right
2- !Unary negation, logical NOTRight-to-left (unary prefix)
3* / %Multiplication, division, moduloLeft-to-right
4+ -Addition, subtraction, string concatenationLeft-to-right
5< <= > >=Relational comparisonLeft-to-right
5== !=Equality and inequalityLeft-to-right
6&&Logical ANDLeft-to-right
7||Logical ORLeft-to-right
8 (lowest)=Assignment / reassignmentRight-to-left

Operator Details

1. Grouping, Call, Access () [] .

Associativity: Left-to-right

Parentheses () group sub-expressions. Square brackets [] perform function calls, array indexing, or tensor indexing/slicing. Dot . accesses struct fields, method calls, or module members.

let result = (1 + 2) * 3       // grouping
let val = matrix[0][1]         // indexing
let x = point.x                 // member access
let y = add(3, 4)               // function call
let slice = tensor[0:5]        // tensor slicing

2. Unary - !

Associativity: Right-to-left (prefix unary)

- negates a numeric value (int or float). ! applies logical NOT to a bool.

let neg = -42
let flipped = !true       // false
let double_neg = -(-5)    // 5

3. Multiplicative * / %

Associativity: Left-to-right

* multiplies numeric values. / divides numeric values (float division for floats, integer division for ints). % computes the integer modulo.

let product = 5 * 3        // 15
let quotient = 10 / 3      // 3 (integer division)
let float_div = 10.0 / 3.0 // 3.333...
let remainder = 10 % 3     // 1

4. Additive + -

Associativity: Left-to-right

+ adds numeric values or concatenates strings. - subtracts numeric values.

let sum = 5 + 3             // 8
let diff = 10 - 3           // 7
let greeting = "Hello, " + "World"  // string concatenation

5. Relational < <= > >=

Associativity: Left-to-right

Compare numeric values. Returns a bool. < less than, <= less than or equal, > greater than, >= greater than or equal.

let a = 5 < 10     // true
let b = 10 <= 5    // false
let c = 8 &gt;= 8     // true

5. Equality == !=

Associativity: Left-to-right

== checks value equality (works on all types). != checks value inequality. String comparison is case-sensitive. Struct comparison checks all fields.

let eq = 5 == 5          // true
let neq = "a" != "b"    // true
let cmp = nil == nil     // true

6. Logical AND &&

Associativity: Left-to-right

Short-circuit logical AND. Both operands must be bool. Evaluates right operand only if left operand is true.

let result = (5 > 0) && (10 < 20)  // true
let short = false && (risky())      // risky() not called

7. Logical OR ||

Associativity: Left-to-right

Short-circuit logical OR. Both operands must be bool. Evaluates right operand only if left operand is false.

let result = (5 < 0) || (10 < 20)   // true
let short = true || (risky())        // risky() not called

8. Assignment =

Associativity: Right-to-left

Reassigns a value to an existing let-bound variable, a struct field, or an array/tensor element. The left side must be an assignable target. Chaining is supported: a = b = 5 assigns 5 to both.

let x = 0
x = 42                    // reassign variable
let rect: Rectangle
rect.width = 100.0        // field assignment
matrix[0][1] = 99         // element assignment
let a = 1
let b = 2
a = b = 10                // both a and b become 10

Other Tokens

TokenDescriptionExample
->Return type arrowfn add() -> int
=>Match case fat arrow1 => print("one")
@Decorator prefix@autograd, @layer
...Ellipsis (tensor all dims)tensor[..., 0:2]
|Pipe operatorx | f | g
:Type annotation / slicingx: int, 0:5
;Statement terminatorlet x = 5;

Related Pages