Skip to content

Overview

Zolo binds names to values with let (immutable), let mut (mutable), const (compile-time), and var (storage-class bindings). This chapter walks each in turn; here is the lay of the land:

A quick tour of every binding form you'll meet in this chapter.

00-overview.zolo
Playground
/// Variables and Constants in Zolo


// Immutable binding (type inferred)

let name = "Zolo"
let age = 1
let pi = 3.14159

// Explicit type annotation

let greeting: str = "Hello, World!"
let count: int = 42
let ratio: float = 0.618

// Mutable binding — requires `mut`

let mut score = 0
score += 10
score += 20
print("Score: {score}")  // 30


// Constants — evaluated at compile time

const MAX_SIZE = 1024
const VERSION = "0.1.0"
const GRAVITY = 9.81

print("Max: {MAX_SIZE}, Version: {VERSION}")

// Multiple bindings

let x = 1
let y = 2
let z = x + y
print("{x} + {y} = {z}")

// Nullable types

let maybe_name: str? = nil
let has_value: int? = 42
print("Name: {maybe_name ?? "anonymous"}")
print("Value: {has_value ?? 0}")

// `var` — alias for `let mut` (preferred for new code)

var counter = 0
counter += 1
counter += 1
print("Counter: {counter}")  // 2


// Storage classes (frontend-only in this version; runtime no-op)

var<atomic> shared_counter = 0
let<lazy> expensive_value = 42
enespt-br