Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is function parameter scope in qore?

Tags:

unix

qore

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...

like image 605
Pavel Kveton Avatar asked Jan 30 '17 07:01

Pavel Kveton


Video Answer


1 Answers

Local variables in the top-level scope are effectively global thread-local variables.

See:

  • https://docs.qore.org/current/lang/html/variables.html#local_variables
  • https://docs.qore.org/current/lang/html/threading.html#threading_and_variables

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).

like image 165
David Nichols Avatar answered Sep 29 '22 12:09

David Nichols