Expressions
This document describes expression evaluation rules in Mux.
Expression Classification
Expressions are categorized by their evaluation behavior:
| Category | Description | Examples |
|---|---|---|
| Value expressions | Produce a value | Literals, variables, operators |
| Place expressions | Denote storage locations | Variables, array elements, fields |
| Void expressions | Produce no value | some function calls |
Primary Expressions
Literals
Identifiers
Parenthesized Expressions
Tuple Literals
Tuples are fixed size pairs with exactly two elements:
Access tuple fields with .left and .right:
List Literals
Type Inference for Lists
The element type is inferred from the contents:
Empty lists require explicit type annotation:
Map Literals
Type Inference
Set Literals
Type Inference
Lambda Expressions
Lambda Capture
Lambdas capture variables from enclosing scope:
Enum Instantiation
Class Instantiation
Generic Classes
Member Access
Field Access
Method Call
Array/List Access
Safe Access with .get()
Range Expressions
Conditional Expressions
Mux does not have a ternary ? : operator. Use if/else as a statement:
Expression Statements
Expressions can be used as statements when side effects are desired:
Type of Expressions
The compiler determines the type of each expression:
| Expression | Type |
|---|---|
| Integer literal | int |
| Float literal | float |
| String literal | string |
| Boolean literal | bool |
| Tuple literal | tuple<T, U> |
| List literal | list<T> (inferred) |
| Identifier | Declared or inferred type |
a + b | Type of a and b (must match) |
a == b | bool |
a && b | bool |
!a | bool |
range(a, b) | list<int> |
| Lambda | func(...) -> ... |
See Also
- Operators - Operator precedence