Built-in namespace usage, Names Default to Here, function local variablesHello, I have a question about namespaces in module scripts and functions within those scripts.
As I understand it, any variable defined where Names Default to Here() is true will be assigned in a "here" namespace. What I am not sure of is the scope of that namespace. Is "here" always scoped as the full script (e.g. within a module) or can it also create variables local to individual functions within a script? What is the right way to make local variables within a function? Is there a way for variables defined in each function to be local to just that function and not to the full script? What I am imagining is something like below.
//Script to define different scopes of variables<BR />Names Default to Here(1); //set variables to be scoped to this script by default<BR />a = 1;<BR />b = 2;<BR /><BR />Function1 = Function({},<BR /> Names Default to Here(1);<BR /> c = 3;<BR />);<BR /><BR />Function2 = Function({},<BR /> Names Default to Here(1);<BR /> d = 4;<BR />);@lbrickweg @jcimini
Re: Built-in namespace usage, Names Default to Here, function local variablesHmm sorry about the formatting there
//Script to define different scopes of variables
Names Default to Here(1); //set variables to be scoped to this script by default
a = 1;
b = 2;
Function1 = Function({},
Names Default to Here(1); //set variables set in Function1 to be scoped only to Function1
c = 3;
);
Function2 = Function({},
Names Default to Here(1); //set variables set in Function2 to be scoped only to Function2
d = 4;
);Re: Built-in namespace usage, Names Default to Here, function local variablesNames Default To Here(1) means that all unqualified symbols used/created during that submission (running a script) will be in the same Here namespace. So it is broader than just a single JSL file. So if A.jsl includes B.jsl while Names Default To Here is enabled, symbols created by A and B will both be available in the same Here namespace.
For function locals, you should use a locals list:
/* Default Local */
slow identity = Function({x}, {Default Local},
x squared = x*x; // unqualified name x squared is defaulted to function local
Sqrt(x squared)
);
/* Or list them explicitly */
slow identity = Function({x}, {x squared},
x squared = x*x; // local because we declared it above
Sqrt(x squared)
);
/* Or qualify them */
slow identity = Function({x},
local:x squared = x*x; // qualify to local explicitly
Sqrt(x squared)
);Re: Built-in namespace usage, Names Default to Here, function local variablesGot it! The 'per submission' language is very helpful.
As a followup, when running different modules from App Builder, do the scripts for each module get included when launching the .jmpapp? Or are the scripts for each module actually submitted separately upon << Create Instance, so that each module has it's own Here namespace?
In short, when using a jmpapp, will Here typically refer to each module, or to the app as a whole?Re: Built-in namespace usage, Names Default to Here, function local variables
@mringqui wrote:
Got it! The 'per submission' language is very helpful.
As a followup, when running different modules from App Builder, do the scripts for each module get included when launching the .jmpapp? Or are the scripts for each module actually submitted separately upon << Create Instance, so that each module has it's own Here namespace?
In short, when using a jmpapp, will Here typically refer to each module, or to the app as a whole?
@EvanMcCorkle