Re: [personal kdb+] Re: Variable scoping

A nested function can refer to globals and its own variables & args but not of any surrounding function’s locals & args. Consider: q)f:{{[y]x+y}} q)g:f 1 q)g {[y]x+y} g)g 2 'a // fails because global a is undefined q)a:3 q)g 2 5 q does not give you the full generality of a Scheme function closure. To do so would require solving the so called upward funarg problem. In the example above, f’s x arg would have to live as long as g refers to the returned function from f. This can complicate things quite a bit.