Variables, Expressions, Scopes & Constants
A trailing semicolon turns an expression into a statement of type ().
11.1 Declaring variables
Mutation requires let mut Yes (also for mutable function parameters: mut v: vector<u64>) No — any local can be reassigned Warning (prefix with _ to silence)
let x = 5; // immutable binding
let mut y = 10; // Sui Move 2024: `mut` required to reassign or &mut-borrow
y = y + x;
let (a, b) = (1, 2); // tuple destructuring
let _ = some_function(); // ignore a droppable result
let z: u64; // declared, assigned later
z = 3;11.2 Everything is an expression
A trailing semicolon turns an expression into a statement of type ().
let max = if (a > b) a else b;
let v = {
let tmp = a * 2;
tmp + 1 // last expression (no semicolon) is the block's value
};11.3 Scopes
Variables live until the end of their block. Values without drop must be consumed before their scope ends — the compiler reports an error otherwise:
{
let c = coin::zero<SUI>(ctx);
// ERROR if we stop here: `c` has no drop ability
c.destroy_zero(); // consumed — OK
}11.4 Constants
Constants are module-private; expose them through a public getter function.
Allowed types: primitives, address, and vector of those.
Constant expressions may use arithmetic and other constants (e.g., const DAY_MS: u64 = 24 * 60 * 60 * 1000;).
Naming: UPPER_SNAKE_CASE for values; EPascalCase (Sui convention) or E_UPPER_SNAKE (Aptos convention) for error codes.
const MAX_SUPPLY: u64 = 1_000_000;
const ADMIN: address = @0xA11CE;
const NAME: vector<u8> = b"My Token";
const EInsufficientFunds: u64 = 1;