Zenth has three ways to declare variables: let, var, and const. All declarations use = for assignment – there is no := operator.

#Immutable Variables with let

let declares an immutable binding. Once assigned, its value cannot change:

let name = "Zenth";
let year = 2026;
let pi = 3.14159;
let active = true;

Attempting to reassign a let variable is a compile-time error:

let x = 5;
x = 10;  // error: cannot assign to immutable variable 'x'

#Mutable Variables with var

var declares a mutable binding that can be reassigned:

var counter = 0;
counter = counter + 1;
counter += 1;
Println(counter);  // 2

#Constants with const

const declares a named constant:

const pi = 3.14159;
const max_size = 1024;

#Built-in Constants

Zenth provides built-in integer limit constants:

ConstantValueDescription
INT_MAX9223372036854775807Maximum Int value (2^63-1)
INT_MIN-9223372036854775808Minimum Int value (-2^63)
let infinity = INT_MAX;  // cleaner than magic numbers

#Type Inference

Types are inferred from the assigned value by default:

let x = 42;        // Int
let y = 3.14;      // Float
let s = "hello";   // Str
let b = true;      // Bool

#Explicit Type Annotations

You can annotate the type explicitly with : Type:

let x: Int = 5;
var name: Str = "Zenth";
let ratio: Float = 0.75;

Type annotations are required on function parameters and return types, but optional on local variables.

#Compound Assignment

Mutable variables support compound assignment operators:

var n = 10;
n += 5;   // n is now 15
n -= 3;   // n is now 12
n *= 2;   // n is now 24
n /= 4;   // n is now 6

#Multiple Assignment

You can assign to multiple variables in a single statement. This is often used to swap values without needing a temporary variable:

var x = 1;
var y = 2;
x, y = y, x;  // x becomes 2, y becomes 1

#Tuple Destructuring

You can destructure tuples directly in let, var, and const declarations:

let (cmd, raw) = "forward 10".split_once(" ");
let value = Int(raw);

Destructuring arity must match the tuple size:

let (a, b) = Tuple(1, 2);      // ok
let (x, y, z) = Tuple(1, 2);   // error

#Increment and Decrement

var i = 0;
i++;  // i is now 1
i--;  // i is now 0

#Summary

KeywordMutableUse case
letNoMost variables – prefer immutable by default
varYesCounters, accumulators, anything that changes
constNoNamed constants

#Naming Rules

User-defined variables must start with a lowercase letter:

let count = 1;       // ok
var total = 0;       // ok
const max_size = 10; // ok

let Count = 1;       // error
var Total = 0;       // error
const MaxSize = 10;  // error