Skip to main content

Expressions

This document describes expression evaluation rules in Mux.

Expression Classification​

Expressions are categorized by their evaluation behavior:

CategoryDescriptionExamples
Value expressionsProduce a valueLiterals, variables, operators
Place expressionsDenote storage locationsVariables, array elements, fields
Void expressionsProduce no valuesome function calls

Primary Expressions​

Literals​

Mux
Loading...

Identifiers​

Mux
Loading...

Parenthesized Expressions​

Mux
Loading...

Tuple Literals​

Tuples are fixed size pairs with exactly two elements:

Mux
Loading...

Access tuple fields with .left and .right:

Mux
Loading...

List Literals​

Mux
Loading...

Type Inference for Lists​

The element type is inferred from the contents:

Mux
Loading...

Empty lists require explicit type annotation:

Mux
Loading...

Map Literals​

Mux
Loading...

Type Inference​

Mux
Loading...

Set Literals​

Mux
Loading...

Type Inference​

Mux
Loading...

Lambda Expressions​

A lambda always declares its return type, like any other function - there is no inference for it:

Mux
Loading...

Lambda Capture​

Lambdas capture variables from enclosing scope:

Mux
Loading...

Enum Instantiation​

Mux
Loading...

Class Instantiation​

Mux
Loading...

Generic Classes​

Mux
Loading...

Member Access​

Mux
Loading...

Field Access​

Mux
Loading...

Method Call​

Mux
Loading...

Array/List Access​

Mux
Loading...

Safe Access with .get()​

Mux
Loading...

Range Expressions​

Mux
Loading...

Conditional Expressions​

Mux does not have a ternary ? : operator. Use if/else as a statement:

Mux
Loading...

Expression Statements​

Expressions can be used as statements when side effects are desired:

Mux
Loading...

Type of Expressions​

The compiler determines the type of each expression:

ExpressionType
Integer literalint
Float literalfloat
String literalstring
Boolean literalbool
Tuple literaltuple<T, U>
List literallist<T> (inferred)
IdentifierDeclared or inferred type
a + bType of a and b (must match)
a == bbool
a && bbool
!abool
range(a, b)list<int>
Lambdafunc(...) -> ...

See Also​