Variable scope behaviour for print() should match everything elseWhat inspired this wish list request?
I spent a bunch of time debugging an issue with variable scope. If {default local} is used within a function (which I almost always do) then the function can't access global variables unless the scope is explicitly specified with :: (which I didn't know). However, Print() will silently go looking for itself even without the :: - and given that Print() is a pretty basic debugging tool, that gets very confusing!
What is the improvement you would like to see?
Print() should behave the same in terms of variable scope as everything else
Why is this idea important?
Current behaviour is illogical and inconsistent.
JMP19.1.1.
Automation and ScriptingRe: Variable scope behaviour for print() should match everything else - Status changed to: Needs InfoHi @JohnJoyceFlusso - Thanks for submitting the wish. Can you provide a script that illustrates this behavior?
Re: Variable scope behaviour for print() should match everything elseHere is a minimal script that illustrates the problem: Print() works but msgbox() doesn't.
NB it's not intended to be a useful function, just to demonstrate the issue.
Unfortunately Print() behaves differently to everything else when it comes to variable scope.
I have never met another language that does such a thing. This seems broken.
My suggestion is that Print() shouldn't be different to everything else.
dummy = "Hello";
test = Function( {},
{default local},
Print( dummy );
msgbox( dummy );
);
test();
Re: Variable scope behaviour for print() should match everything elseApologies for confusing matters with msgbox() which is actually mine, not built-in.
Here's an example that does show my point ... the first attempt at radio buttons shows no options, as "options" isn't defined locally; and yet print() can magically access it.
Once I define options locally, the same radio buttons work the second time.
The point is that print() shouldn't behave differently to anything else, as it makes using it as a debug tool somewhat fraught.
options = {"A", "B"};
test = Function( {},
{default local},
Print( options );
New Window( "Pick one",
<<MODAL></MODAL>
Re: Variable scope behaviour for print() should match everything else@JohnJoyceFlusso
You can still access the "options" variable from inside the function using eval( eval expr( ) ). This works for me:
options = {"A", "B"};
test = Function( {},
{default local},
Print( options );
eval( eval expr( New Window( "Pick one",
<<MODAL></MODAL>Re: Variable scope behaviour for print() should match everything elseThanks, yes it does (as does accessing 'options' as ::options, which the support folks pointed out)
My issue remains that Print() behaves differently to everything else, which is illogical.