--- title: Operators, Macros & Closures description: Binary, prefix, and postfix operators, macro calls, and closure expressions. icon: Plus --- ### Binary Operators | Operator | Description | |----------|----------------------| | `+` | Addition | | `-` | Subtraction | | `*` | Multiplication | | `/` | Division | | `%` | Modulus | | `==` | Equality | | `!=` | Inequality | | `<` | Less than | | `>` | Greater than | | `<=` | Less or equal | | `>=` | Greater or equal | | `&&` | Logical AND | | `\|\|` | Logical OR | | `&` | Bitwise AND | | `\|` | Bitwise OR | | `^` | Bitwise XOR | | `<<` | Left shift | | `>>` | Right shift | | `=` | Assignment | | `+=` | Add assign | | `-=` | Subtract assign | | `*=` | Multiply assign | | `/=` | Divide assign | | `%=` | Modulus assign | | `&=` | Bitwise AND assign | | `\|=` | Bitwise OR assign | | `^=` | Bitwise XOR assign | | `<<=` | Left shift assign | | `>>=` | Right shift assign | | `..` | Range (exclusive) | | `..=` | Range (inclusive) | | `->` | Pointer write | ### Prefix Operators | Operator | Description | |----------|-------------------| | `*` | Dereference | | `&` | Reference | | `&mut` | Mutable reference | | `!` | Logical NOT | | `-` | Numeric negation | ### Postfix Operators | Operator | Description | |------------|----------------------| | `.field` | Field access | | `.0` | Tuple field access | | `()` | Function call | | `[]` | Index | | `{ f: v }` | Struct literal | | `as Type` | Type cast | | `?` | Try (error prop) | | `++` | Increment | | `--` | Decrement | | `!()` | Macro call (paren) | | `![]` | Macro call (bracket) | | `!{}` | Macro call (brace) | ### Macros Mist reuses Rust's macro system directly: ```mist println!("hello"); assert_eq!(a, b); vec![1, 2, 3]; ``` Macro calls use `!` followed by parentheses, brackets, or braces. ### Closures ```mist let add = (a, b) => a + b; let result = add(2, 3); // 5 let square = f64 x => x * x; ``` Closures can have explicit return types: ```mist let transform = i32 x => { x * 2 }; ```