42 lines
1.0 KiB
Plaintext
42 lines
1.0 KiB
Plaintext
---
|
|
title: Variables
|
|
description: Variable declarations, mutability, type annotations, and destructuring.
|
|
icon: Variable
|
|
---
|
|
|
|
```mist
|
|
let x = 42; // Type-inferred immutable
|
|
let mut y = 10; // Mutable variable
|
|
i32 z = 100; // Explicit type annotation
|
|
str& s = "hello"; // Typed string reference
|
|
bool b = true; // Typed boolean
|
|
f64 f = 3.14; // Typed float
|
|
(i32, str&) as x, y = (1, "hello"); // Typed tuple destructuring
|
|
let (a, b) = (1, "two"); // Destructuring
|
|
let (x, (y, z)) = (1, (2, 3)); // Nested destructuring
|
|
```
|
|
|
|
Variable declarations follow either of two forms:
|
|
|
|
```mist
|
|
let <pattern> [= <expr>];
|
|
<type> <pattern> [= <expr>];
|
|
```
|
|
|
|
### Tuple Variable Declarations
|
|
|
|
Tuple variables can be declared with explicit type annotations using `as`:
|
|
|
|
```mist
|
|
(i32, bool) (x, y) as = (1, true);
|
|
|
|
i32 a, b = (1, 2, 3);
|
|
```
|
|
|
|
### Const and Static
|
|
|
|
```mist
|
|
const MAX: i32 = 100;
|
|
static NAME: str& = "hello";
|
|
```
|