Summary
Nodus closures cannot assign to variables captured from an enclosing let scope:
let count = 0i
let inc = fn() {
count = count + 1i // ERROR: cannot assign to captured variable
}
The documented workaround is a quoted-key map:
let state = {"count": 0i}
let inc = fn() {
state["count"] = state["count"] + 1i // works
}
This workaround is functional but adds significant cognitive overhead for any program that accumulates state across recursive calls — schema validators, tree traversals, parser state machines.
Impact
This is the primary leverage ceiling for stateful data processing programs. The audit identifies "a stateful recursive data processor" as the program type hardest to write in Nodus despite being within its stated scope.
Why the restriction exists
Nodus closures capture variables by value at closure creation time. Assignment to a captured variable in Python's closure model requires nonlocal; Nodus has no equivalent keyword. The map workaround works because maps are mutable objects captured by reference.
Fix direction (v5)
Two options:
- Add a
mut keyword to let that signals the variable is assignable from inner closures: let mut count = 0i
- Allow outer
let assignment via upvalue mutation — detect at compile time that a variable is being assigned from an inner scope and emit a SET_UPVALUE opcode instead of SET_LOCAL
Option 2 is lower surface area; option 1 is more explicit. Either would make the closure mutation workaround unnecessary for the common case.
Affected versions
v4.0.0 (current). Noted in System Limits Audit §5 (Leverage Boundary).
Summary
Nodus closures cannot assign to variables captured from an enclosing
letscope:The documented workaround is a quoted-key map:
This workaround is functional but adds significant cognitive overhead for any program that accumulates state across recursive calls — schema validators, tree traversals, parser state machines.
Impact
This is the primary leverage ceiling for stateful data processing programs. The audit identifies "a stateful recursive data processor" as the program type hardest to write in Nodus despite being within its stated scope.
Why the restriction exists
Nodus closures capture variables by value at closure creation time. Assignment to a captured variable in Python's closure model requires
nonlocal; Nodus has no equivalent keyword. The map workaround works because maps are mutable objects captured by reference.Fix direction (v5)
Two options:
mutkeyword toletthat signals the variable is assignable from inner closures:let mut count = 0iletassignment via upvalue mutation — detect at compile time that a variable is being assigned from an inner scope and emit aSET_UPVALUEopcode instead ofSET_LOCALOption 2 is lower surface area; option 1 is more explicit. Either would make the closure mutation workaround unnecessary for the common case.
Affected versions
v4.0.0 (current). Noted in System Limits Audit §5 (Leverage Boundary).