LEGACY DOCS · 12.0Stable is 13.2. This page stays because it still owns historical or unchanged contracts.CURRENT 13.2 →
RELEASE LINE13.2 STABLE13.1 PREDECESSOR13.0 PREVIOUS12.4 NATIVE MIRARCHIVE

V12.0 BASE CONTRACT

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

closures.dbyDOWNLOADOPEN RAW
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
DBY · 211 BSHA-256 2e5b65ee91efbb0e44a77c495bdc52e858ea430949af7e033a3cc0050d5d64e9

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

WEBSITE V12 FIXTURE