cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
cnattrass
Level II

Dealing with Include function and Namespaces

JMP uses the global namespace as the default namespace for any new script, the way to specify a "local" namespace is the Names Default to Here(1)command. My question is this, when I include a file that has the Names Default to Here(1)  at the top it will bring over the names/variables from the child script. However, if I define

include("filepath/name.ext", << New  Context, << NamesDefaultToHere) 

 it will keep the namespaces separate.. What is the reasoning behind this? It seems like it should be doing the same thing? Since I am using an Include statement does it assume I want to absorb the names from the child script?

 

The below set returns x = 10, even though NamesDefaultToHere(1) is in script B

Script A

x = 5;
include("filepath/script_B.jsl");
show(x);

Script B

namesDefaultToHere(1);
x = 10;

 

While this one returns x =5, because I had the namesDefaultToHere in the include statement

Script A

x = 5;
include("filepath/script_B.jsl", << newContext, <<namesDefaultToHere);
show(x);

Script B

namesDefaultToHere(1);
x = 10 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ryan_Gilmore
Community Manager Community Manager

Re: Dealing with Include function and Namespaces

@drewfoglia and @EvanMcCorkle gave an excellent presentation at Discovery Summit in Tuscon 2019 entitled Essential Scripting for Efficiency and Reproducibility: Do Less to Do More (2019-US-TUT-290) which discusses this topic.

 

One of the slides (22) provides misconceptions about Names Default to Here, one of which is that each JSL file has its own Here context. This is true if each script is run separately but when including JSL file B in JSL file A, B shares A's Here context. 

 

In the first example, using the rules for resolving names, JMP finds X in the Here namespace and shows the value of 10.

 

In the second example, use of "new context" is creating an anonymous namespace in which script B is run. In this case, X is not part of the Here namespace so the value found in the Global namespace is shown.

 

 

View solution in original post

1 REPLY 1
Ryan_Gilmore
Community Manager Community Manager

Re: Dealing with Include function and Namespaces

@drewfoglia and @EvanMcCorkle gave an excellent presentation at Discovery Summit in Tuscon 2019 entitled Essential Scripting for Efficiency and Reproducibility: Do Less to Do More (2019-US-TUT-290) which discusses this topic.

 

One of the slides (22) provides misconceptions about Names Default to Here, one of which is that each JSL file has its own Here context. This is true if each script is run separately but when including JSL file B in JSL file A, B shares A's Here context. 

 

In the first example, using the rules for resolving names, JMP finds X in the Here namespace and shows the value of 10.

 

In the second example, use of "new context" is creating an anonymous namespace in which script B is run. In this case, X is not part of the Here namespace so the value found in the Global namespace is shown.