# Re: \[personal kdb+\] Re: Variable scoping

**URL:** <https://forum.kx.com/t/re-personal-kdb-re-variable-scoping/5777>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [September 10, 2008, 8:02pm UTC](https://forum.kx.com/t/re-personal-kdb-re-variable-scoping/5777 "2008-09-10T20:02:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bakul\_Shah](https://avatars.discourse-cdn.com/v4/letter/b/6bbea6/32.png) [@Bakul\_Shah](https://forum.kx.com/u/Bakul_Shah)\
**Post date:** [September 10, 2008, 8:02pm UTC](https://forum.kx.com/t/re-personal-kdb-re-variable-scoping/5777/1 "2008-09-10T20:02:00Z")

</div>

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.
