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.
Related topics
Topic | Replies | Views | Activity | |
---|---|---|---|---|
Variable scoping | 3 | 0 | September 10, 2008 | |
rank error when calling a nested function. | 1 | 0 | January 30, 2014 | |
Problem related to local variables | 1 | 0 | August 30, 2018 | |
Lexical scope for local vars in q | 0 | 0 | June 28, 2016 | |
access local variables in value | 10 | 0 | May 29, 2012 |