The out Keyword
So far, every memory rule has been inferred. The one — and only — explicit memory concept in the language is out. Mark a parameter out to let a function modify a caller's variable in place.
use system.io
use system.collections.list
// `out` lets a function modify a caller's variable in place.
// The only memory-related keyword in the language.
fn inc(n out int)
n = n + 1
fn append_99(list out [int])
list.push(99)
fn main()
var x = 41
inc(x)
println(f"{x}") // 42
var items = List([1, 2])
append_99(items)
println(f"{items.length()}") // 3
// Passing a `let` binding to an `out` parameter is a compile error —
// out parameters always require a mutable variable.
Rules at a glance
- The argument passed to an
outparameter must be avar. Passing aletis a compile error. - The same variable cannot appear twice as
outin a single call (no aliasing through the back door). - Types must match exactly — no implicit coercion.
- For small auto-copy types,
outcompiles to a mutable reference (no allocation). For managed/large types, the value is moved in and moved back out — ownership transfers to the callee and returns to the caller.
That's the whole memory-keyword surface. No lifetimes, no &mut, no borrow-vs-move distinctions to memorize.