Bindings and Constants
Bindings
Section titled “Bindings”A binding connects a name to a value. In Vertex, bindings are immutable by default:
let greeting = "Hello"let count: Int = 42 // explicit type annotationAttempting to reassign an immutable binding is a compile-time error:
let x = 10x = 20 // error E101: cannot assign to immutable binding 'x'For values that need to change, use mutable let:
mutable let total = 0total = total + 10total = total + 20debug total // 30The mutable keyword is intentionally verbose. Mutation should feel deliberate.
Constants
Section titled “Constants”Module-level constants are declared with const and must be scalar literals:
const max_retries = 3const api_version: String = "v2"const pi: Double = 3.14159pub const discount_rate = 10 // visible to other modulesConstants are always immutable. No mutable const is allowed.
Public constants can be imported by other modules:
import config.{ discount_rate }
debug discount_rate // 10Underscore 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 suppressedlet _temp = expensive_setup() // W002 suppressedThe 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}Next steps
Section titled “Next steps”- Bindings reference
- Constants reference
- Compiler Diagnostics, W002, W003, W004