I'm a bit puzzled by variable scope in qore 0.8.12. It seems that function parameters have the same scope as the global variables - is that possible, or am I doing something wrong?
3.1.0 kveton@kvela ~$ cat zk1.q
%new-style
%strict-args
sub fun(string v)
{
print("xxx\n");
}
string v = "zzz";
3.1.0 kveton@kvela ~$ qore zk1.q
unhandled QORE System exception thrown in TID 1 at 2017-01-30 08:10:32.612137 Mon +01:00 (CET) at zk1.q:4
PARSE-ERROR: local variable 'v' was already declared in the same block at zk1.q:9
Thanks for explanation...
Local variables in the top-level scope are effectively global thread-local variables.
See:
This makes it impossible to use the same variable name as a parameter variable (which is a local variable in the scope of the function, method, or closure being defined).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With