Closures
Explicit capture lists create concrete environments in source order.
DByte 12.0 · Language
Contract§
pub fn kernel_main() -> int:
let factor: u32 = 2 as u32
let add = fn [borrow factor](value: u32) -> u32:
return value + factor
if add(40 as u32) != (42 as u32):
return 1
return 0
Source: source-examples/v12.0.0/closures.dby
Mechanics§
An explicit capture list defines a concrete environment aggregate in source order. The DByte call ABI supplies a hidden environment pointer before ordinary parameters.
Validation and failure§
Captures establish immediately: move moves now, borrow remains live, and borrow mut stays exclusive. Capturing environments may not allocate, erase type or escape in v12.
Evidence and boundary§
HIR records ClosureId and capture order; native execution reads borrowed captures through the generated environment.
Executable example§
pub fn kernel_main() -> int:
let factor: u32 = 2 as u32
let add = fn [borrow factor](value: u32) -> u32:
return value + factor
if add(40 as u32) != (42 as u32):
return 1
return 0