Skip to content

Bindings and Constants

A binding connects a name to a value. In Vertex, bindings are immutable by default:

let greeting = "Hello"
let count: Int = 42 // explicit type annotation

Attempting to reassign an immutable binding is a compile-time error:

let x = 10
x = 20 // error E101: cannot assign to immutable binding 'x'

For values that need to change, use mutable let:

mutable let total = 0
total = total + 10
total = total + 20
debug total // 30

The mutable keyword is intentionally verbose. Mutation should feel deliberate.

Module-level constants are declared with const and must be scalar literals:

const max_retries = 3
const api_version: String = "v2"
const pi: Double = 3.14159
pub const discount_rate = 10 // visible to other modules

Constants are always immutable. No mutable const is allowed.

Public constants can be imported by other modules:

import config.{ discount_rate }
debug discount_rate // 10

Underscore prefix: silencing unused warnings

Section titled “Underscore prefix: silencing unused warnings”

Prefixing a name with _ tells the compiler you intentionally don’t use it:

fn process(_ignored: String): Int { 42 } // W003 suppressed
let _temp = expensive_setup() // W002 suppressed

The bare _ wildcard in patterns is a different concept. It discards a value entirely:

match result {
Ok(value) => value,
Error(_) => 0, // _ discards the error; not a named binding
}