Closures
Closures are arrow-function expressions. They capture variables from the enclosing scope — including captured-variable mutation — and are lowered correctly to both TypeScript and Python.
Inline closures
Use an arrow function anywhere an expression is accepted, such as a .map or .filter callback:
nums.map((x) => { return x * 2; })
items.filter((x) => { const ok = x % 2 === 0; return ok; })
items.map((x) => { if (x > 2) { return x * 10; } return x; })Captured variables
A closure reads free variables from its enclosing scope:
let name=scale value="(x) => { const y = x * factor; return y; }"Captured-variable mutation
A closure can also mutate a captured variable. The shared binding is preserved across calls and lowered identically on both targets:
let name=count value="0" kind=let
let name=inc value="() => { count++; return 0; }"
let name=get value="() => { return count; }"
do value="inc()"
do value="inc()"
return value="get()" # → 2Fail-closed boundaries
Constructs that cannot be lowered identically to both runtimes are rejected at compile time rather than guessed. A closure that references this, for example, is rejected (closure-this) — keeping TypeScript and Python behavior in lockstep.