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.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
hogi
Level XIII

Table script - completed?

When triggering a Tables script from another script, how can I check if a table script was completed (without errors)?

 

Adding a return function is not allowed:

hogi_0-1690895010741.png

 

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << run Script( "Bivariate" );
dt << New Script(
	"test", JSL Quote(
		print(1);
		return(1);	
),As String( 1 ));


dt << New Script(
	"test2", JSL Quote(
		New Namespace("myScript");
		myScript:finished=0;
print(1);
myScript:finished=1;
),
	As String( 1 )
);

If( Not( dt << run Script( "test" ) ),
	Stop()
);

dt << run Script( "test2" );
If( Not( myScript:finished ),
	Stop()
);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: Table script - completed?

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

dt << deletescripts( "test" );

dt << New Script(
	"test", JSL Quote(
		if(test<0,
			0 // either this is the last value from the if
		,
			print("ok");
			1 // or this is the last value from the if
		); // the if() value is either 0 or 1
	), // the script's value is the last statement executed value
	As String( 1 )
);

test = 37;
Show( test, dt << run Script( "test" ) ); // "ok",1

test = -42;
Show( test, dt << run Script( "test" ) ); // 0

 edit: include() works the same way.

Craige

View solution in original post

5 REPLIES 5
Craige_Hales
Super User

Re: Table script - completed?

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

dt << deletescripts( "test" );

dt << New Script(
	"test", JSL Quote(
		if(test<0,
			0 // either this is the last value from the if
		,
			print("ok");
			1 // or this is the last value from the if
		); // the if() value is either 0 or 1
	), // the script's value is the last statement executed value
	As String( 1 )
);

test = 37;
Show( test, dt << run Script( "test" ) ); // "ok",1

test = -42;
Show( test, dt << run Script( "test" ) ); // 0

 edit: include() works the same way.

Craige
hogi
Level XIII

Re: Table script - completed?

Oh, so simple :)

Thanks @Craige_Hales 

hogi
Level XIII

Re: Table script - completed?

For functions there is no difference between the two variants? 

 

testFunc1= Function({},return(1));
testFunc2= Function({},1);

show(testFunc1);
show(testFunc2);
Craige_Hales
Super User

Re: Table script - completed?

return(1) has a major advantage if it is nested inside for loops and if statements: it returns the answer without needing to be otherwise positioned to be the last expression evaluated. The implementation of the return(1) in C++ is slower than just ending with the desired expression; you'll notice on short functions that are called millions of times. So in your example I tend to write

testFunc2= Function({},
 /*return*/ 1
);

with the comment. Or use return(1) if clarity is more important. The break() and continue() statements work much the same. Using them for clarity, or in a way that executes them infrequently is perfect.

Craige
hogi
Level XIII

Re: Table script - completed?

Nice idea with the /*return*/ comment.

I already deleted one of my "1"s - because it looked so unnecessary ;)
Some days later, without the direct connection to the deleted "1", it was quite hard to find out what's going wrong ...

Recommended Articles