I noticed that namespace variables behaviour very differently when used within q-sql. For an illustration, please refer to the code below.
\d .namespace
HELLO:`World
DATA:(S:HelloWorld;V:2?100f)
fun1:{show HELLO;show DATA}
fun2:{show select from DATA where V=HELLO}
\d .
.namespace.fun1/ok
.namespace.fun2/error!
Calling .namespace.fun1 yields that designed output with .namespace.HELLO and .namespace.DATA shown.
But calling .namespace.fun2 yeilds 'HELLO error (but not 'DATA error).
After going through the explanations about namespace usage in Wiki, I’m still not very sure if there is a special scoping rule being applied only to q-sql.
Could anyone with the knowledge help to shed some light on this behaviour?
Value on function shows that table comes in context section which means it is read from context in which the function is defined (and not the one function belongs to) whereas query filters comes in constant section which means they are read from context from in which function is being called.
So when you call this function from global namespace , it tries to find HELLO variable in that namespace and gives the error.
Thanks? Rahul. This explanation is clear as crystal.
May I know where I can find the exact scoping rule of constants? I know the variable scoping rule well in Q4M, but I don’t recall reading about constant scoping rules anywhere.