Publish a refutable binding
An ordinary let pattern must always match. A refutable pattern adds else whose block leaves the surrounding scope through return, break, or continue.
That divergence proves the successful bindings exist afterward. The initializer runs once, and failure cannot use names that were never bound.
fn first(values: [int]) -> string {
let [head, .._] = values else { return "empty" }
"first $head"
}
fn main() {
println(first([5, 6]))
println(first([]))
}
Examples use the moon toolchain version shown beside each result.
Output & diagnostics
Expected: first 5 empty
Ctrl/⌘+Enter runs the current lesson.