Code: Select all
f() {
local a := ""
c() {
local b := a
}
cc() {
ccc() {
c()
}
ccc()
}
loop {
cc()
}
}
f()
Code: Select all
f() {
local a := ""
c() {
local b := a
}
cc() {
ccc() {
c()
}
ccc()
}
loop {
cc()
}
}
f()
Nested Functions wrote:By default, a nested function automatically "captures" a non-static local variable of an outer function when the following requirements are met:A nested function which has captured variables is known as a closure.
- The outer function must refer to the variable in at least one of the following ways:
- By declaring it with local, or as a parameter or nested function.
- As the non-dynamic target of an assignment or the reference operator (&).
- The inner function (or a function nested inside it) must refer to the variable non-dynamically.
Closures wrote:A nested function is automatically a closure if it captures any non-static local variables of the outer function. The variable corresponding to the closure itself (such as activate) is also a non-static local variable, so any nested functions which refer to a closure are automatically closures.
Each call to the outer function creates new closures, distinct from any previous calls.