Page 1 of 1

Initialize variables in GLOBAL PROC

Posted: May 7th, 2022, 5:11 pm
by htuser
Dear CSPro Developer Team,
This is a long ago issue and it seem to be a compiler limitation...
string usern=Maketext ("%s",getusername());
string usern=getusername();
In CSPro Logic it's impossible to initialize variables with the result of functions...

Please, do you have some workaround?

Thanks in advance for your response.

Re: Initialize variables in GLOBAL PROC

Posted: May 9th, 2022, 8:09 am
by Gregory Martin
In the future we might support this, as it would be useful at times. The problem is we need to think through some of the challenges; for example:
function Func1()
    exit tonumber(invoke("Func2"));
end;

numeric v1 = Func1();

function Func2()
    exit v1;
end;
What would v1 be?

The rules for how stuff like this is evaluated would need to be thought through. For now, assigning initial values in the application preproc is a fairly simple process, though perhaps not as explicit/clear as what you are trying to do.

Re: Initialize variables in GLOBAL PROC

Posted: May 10th, 2022, 6:00 am
by htuser
Hi Greg,
Thanks for your support.
What would v1 be?
This problem have been solved in several programming languages using technical such as forward declaration, among others.
https://www.geeksforgeeks.org/recursive-functions/
https://en.wikipedia.org/wiki/Forward_declaration
I rather think as you already mentioned it, this problem is regarding the one pass compiler limitation of CSPro Logic...

I need this because of, as you know, i'm thinking about ready to use packages, so i need more ways to do things dynamically.
For example, define dynamic paths global variables able to be used in syncs user defined functions etc.
Rather than having
string dataFolder = "..\main_application\data\";
i would use path namespace object to get it dynamically in the GLOBAL PROC.


Best,