Skip to content

Closure

class Closure

Lambda (anonymous) function object with captured environment

Closures implement first-class functions in WAL: - Capture a lexical environment at definition time - Store parameter list (args) - Store function body (expression) - Support recursive self-reference via name

Evaluation: - Parameters bound to arguments in captured environment - Body evaluated with new bindings - Returns the body's evaluation result

1
2
3
4
5
6
7
8
(lambda (x y) (+ x y))
↓
Closure {
  environment: <current>,
  args: (x y),
  expression: (+ x y),
  name: "lambda"
}
See
Environment for scope chains
See
SEval::eval_closure