cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

JMP Wish List

We want to hear your ideas for improving JMP. Share them here.
Choose Language Hide Translation Bar
0 Kudos

Variable scope behaviour for print() should match everything else

What 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.

5 Comments
scott_allen
Staff
Status changed to: Needs Info

Hi @JohnJoyceFlusso  - Thanks for submitting the wish. Can you provide a script that illustrates this behavior?

JohnJoyceFlusso
Level I

Here 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();
JohnJoyceFlusso
Level I

Apologies 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,
		V List Box( rb = Radio Box( options ), Button Box( "OK", sel = rb << get selected ) )
	);

	options = {"A", "B"};
	New Window( "Pick one",
		<<modal,
		V List Box( rb = Radio Box( options ), Button Box( "OK", sel = rb << get selected ) )
	);

	Return( sel );
);

test();

 

 

scott_allen
Staff

@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,
		V List Box( rb = Radio Box( expr(options) ), Button Box( "OK", sel = rb << get selected ) )
	)));

	Return( sel );
);

test();
JohnJoyceFlusso
Level I

Thanks, 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.