cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
nthai
Level III

How to access Here namespace during entered Local Here namespace?

Hi all,

I'm having trouble to access the Here namespace during entered Local Here namespace. My example script as follow:

 

Names Default To Here(1);
Delete Symbols();
// Declare a variable in the "Here" scope
x = "Variable";
Local Here(
    // Access the "Here" scope variable
    y = Eval(Namespace("here") << Get("x"));
    Show(y);
);

When I used debugger, can clearly see after entered Local Here, it has 2 Here scopes. My guess is one from Here, and the other from Local Here. I have tried several approaches, but none works so far.

1 ACCEPTED SOLUTION

Accepted Solutions
hogi
Level XII

Re: How to access Here namespace during entered Local Here namespace?

You can access any namespace if you have the "key":
At a moment with access to the namespace, just create a reference to the namespace and use it as the key.


Important: 
If you store the key in the Here namespace, it's not accessible from outside.

To make it accessible from everywhere, just store it in the global namespace.
-> global "polluted" by one key variable - not by ~ 80 variables anymore : )

JMP will handle the anonymous namespace and delete it once it's not needed anymore.

 

Names Default To Here(1);
Delete Symbols();
// Declare a variable in the outer "Here" scope
x = "Variable";
//myHere = Namespace("here"); // created inside HERE ->  not accessible from local here
::myHere= Namespace("here"); // so let's create the reference in the global NS
z=5;
Local Here(
	:: mylocalHere= Namespace("here"); // will be deleted after local HERE
    // the  same for "myHere": it will be deleted once the code is finished AND the editor is closed -> very convenient

	::mypersistentNamespace = New Namespace("persistent"); // manually created -> persistent
	persistent:y="still alive";

    // Access the outer "Here" scope variable via the namespace reference
    y = Eval(::myHere << Get value ("z"));
    Show(y);
);

Show(:: mylocalHere); // deleted
Show(::mypersistentNamespace) // alive

 

View solution in original post

7 REPLIES 7
jthi
Super User

Re: How to access Here namespace during entered Local Here namespace?

I think you can't directly (that is kinda the purpose of Local Here)

 

jthi_1-1727855324539.png

Programming Functions (jmp.com)

 

-Jarmo
nthai
Level III

Re: How to access Here namespace during entered Local Here namespace?

Hi jthi,

 

If that the case, could you advise what is the best approach for "root namespace"? I'm using Global namespace right now and intent to leverage to Here namespace and avoid namespace pollute. My script is involved ~80 variables.

jthi
Super User

Re: How to access Here namespace during entered Local Here namespace?

Depends on what you are doing. You can utilize named namespaces, anonymous namespaces, global, here, local,... but still, I would almost always start my scripts with Names Default To Here(1);

-Jarmo
hogi
Level XII

Re: How to access Here namespace during entered Local Here namespace?

Without the Names Default to HERE(1)  the generated variables will "pollute" the Global Namespace.

With the Names Default to HERE(1)  the generated variables will "pollute" the Here Namespace.

 

To organize the variables, you can create your own namespace and create the variables there:

 

Names Default To Here(1);
Delete Symbols();
// Declare a variable in the "Here" scope
x = "Variable";

//get the value
ns = Namespace("here");
val = ns << Get Value("x");
Print(val);
Show(x);


new namespace("myNS");
NS:x = "variable";
Show(NS:x)
hogi
Level XII

Re: How to access Here namespace during entered Local Here namespace?

It's strange that there are two HERE namespaces and that they show the same content - the one of the local here.
When you step out of the local here, there is just a single Here namespace and it correctly hows the content of the Names Default to Here(1) one.

Another issue with JSL debugger:
since JMP15 the local namespace of functions is not accessible anymore: Function locals in JSL Debugger 

 

 

nthai
Level III

Re: How to access Here namespace during entered Local Here namespace?

I have checked. Seems Local Here can access Global and named namespace just fine. However, how i am suppose to initial an anonymous namespace?

Basically my idea is end-user doesn't need to care about the variables, and those variables/namespace will be closed after the data table associates with was closed.
hogi
Level XII

Re: How to access Here namespace during entered Local Here namespace?

You can access any namespace if you have the "key":
At a moment with access to the namespace, just create a reference to the namespace and use it as the key.


Important: 
If you store the key in the Here namespace, it's not accessible from outside.

To make it accessible from everywhere, just store it in the global namespace.
-> global "polluted" by one key variable - not by ~ 80 variables anymore : )

JMP will handle the anonymous namespace and delete it once it's not needed anymore.

 

Names Default To Here(1);
Delete Symbols();
// Declare a variable in the outer "Here" scope
x = "Variable";
//myHere = Namespace("here"); // created inside HERE ->  not accessible from local here
::myHere= Namespace("here"); // so let's create the reference in the global NS
z=5;
Local Here(
	:: mylocalHere= Namespace("here"); // will be deleted after local HERE
    // the  same for "myHere": it will be deleted once the code is finished AND the editor is closed -> very convenient

	::mypersistentNamespace = New Namespace("persistent"); // manually created -> persistent
	persistent:y="still alive";

    // Access the outer "Here" scope variable via the namespace reference
    y = Eval(::myHere << Get value ("z"));
    Show(y);
);

Show(:: mylocalHere); // deleted
Show(::mypersistentNamespace) // alive