phase: 20.49 COMPLETE; 20.50 Flow+String minimal reps; 20.51 selfhost v0/v1 minimal (Option A/B); hv1-inline binop/unop/copy; docs + run_all + CURRENT_TASK -> 21.0
This commit is contained in:
10
apps/fn-capture-demo/main.hako
Normal file
10
apps/fn-capture-demo/main.hako
Normal file
@ -0,0 +1,10 @@
|
||||
// Capture demo:
|
||||
// - locals are captured by reference using RefCellBox (use .get/.set)
|
||||
// - non-locals (global/statics) are captured by value (P1)
|
||||
local y = 41
|
||||
local ycell = new RefCellBox(y)
|
||||
local f = fn(x){ ycell.set(ycell.get() + 1); x + ycell.get() }
|
||||
// outer writes through RefCellBox
|
||||
// y itself remains 41; ycell holds the mutable state
|
||||
local con = new ConsoleBox()
|
||||
con.println(f(1)) // 43 (ycell started 41, incremented to 42, x=1 -> 43)
|
||||
Reference in New Issue
Block a user