cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Choose Language Hide Translation Bar
View Original Published Thread

Insert a Expr() object into another script as an unevaluated Expr() object to be used later?

robot
Level VI

Adding to @jthi 's answer at Insert contents of Parse expression rather than variable name into New Script, how to insert a Expr() object into another script as an unevaluated Expr() object to be used later?

 

I am using JMP 18.1.2

 

Names Default To Here( 1 );

dt = New Table( "My Table" );

e1 = Expr(
	Print( "Run some code." )
);

e2 = Expr(
	e1;
	Print( "Run some other code." );
);

e3 = Eval Expr(
	Expr( Name Expr( e1 ) ); // Define, but do not evaluate e1 here.
	Expr( Name Expr( e2 ) ); // Evaluate e1 here.
);
Show( e3 );

Eval( Eval Expr( dt << New Script( "Test", Expr( Name Expr( e3 ) ) ) ) );
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User


Re: Insert a Expr() object into another script as an unevaluated Expr() object to be used later?

You can also wrap it into extra Expr

Names Default To Here(1);

dt = New Table("My Table");

e0 = Expr(e1 = Expr(Print("Run some code.")));

e2 = Expr(
	e1;
	Print("Run some other code.");
);

e3 = Eval Expr(
	Expr(Name Expr(e0)); // Define, but do not evaluate e1 here.
	Expr(Name Expr(e2)); // Evaluate e1 here.
);
Show(e3);

Eval(Eval Expr(dt << New Script("Test", Expr(Name Expr(e3)))));

jthi_0-1742833430942.png

 

-Jarmo

View solution in original post

5 REPLIES 5
hogi
Level XII


Re: Insert a Expr() object into another script as an unevaluated Expr() object to be used later?

A nice trick in JMP:
you can press the Enter Key on the numeric keyboard to run one line of code.
This is very helpful for debugging.

another trick:
right click into the script window and activate:

hogi_0-1742594035590.png

 

 

the last trick:
mark the Eval Expr(...) inside an Eval() and "run" it to check if the expression is what you expect:

hogi_1-1742594140326.png

 

This shows that where you write 

// Evaluate e1 here.

Name Expr just takes the Expression which is stored in the variable. It doesn't evaluate it. e1 stays  e1.

Edit:
But maybe this is what you want to achieve? No question - just a comment?
The JSL script will write "e1" into the table script.
And JMP will try to evaluate e1 when the user runs the table script.

This means: you have to define e1 in the context of the data table, otherwise you will get an error message:

hogi_0-1742630908107.png

 

[e1 is just defined within the here namespace of the script]

jthi
Super User


Re: Insert a Expr() object into another script as an unevaluated Expr() object to be used later?

I'm not exactly sure what you are going for as e1 has already been defined on line 5. What do you wish to have inside e3? Something like this

e1 = Expr(Print("Code"));
e1; //e2
Print("Code2"); //e2

Or

e1 = Expr(Print("Code"));
Print("Code");
Print("Code2"); //e2
-Jarmo
robot
Level VI


Re: Insert a Expr() object into another script as an unevaluated Expr() object to be used later?

Thanks @hogi and @jthi for the input.  I was able to achieve the result I was looking for by using a function.

 

Names Default To Here( 1 );

dt = New Table( "My Table" );

e1 = Expr(
	f1 = Function( {},
		{Default Local},
		Print( "Run some code." )
	)
);

e2 = Expr(
	f1();
	Print( "Run some other code." );
);

e3 = Expr(
	f1();
	Print( "Run even more code." );
);

e4 = Eval Expr(
	Expr( Name Expr( e1 ) ); // Define, but do not evaluate e1 here.
	Expr( Name Expr( e2 ) ); // Evaluate e1 here.
	Expr( Name Expr( e3 ) ); // Evaluate e1 here.
);

Eval( Eval Expr( dt << New Script( "Test", Expr( Name Expr( e4 ) ) ) ) );
jthi
Super User


Re: Insert a Expr() object into another script as an unevaluated Expr() object to be used later?

You can also wrap it into extra Expr

Names Default To Here(1);

dt = New Table("My Table");

e0 = Expr(e1 = Expr(Print("Run some code.")));

e2 = Expr(
	e1;
	Print("Run some other code.");
);

e3 = Eval Expr(
	Expr(Name Expr(e0)); // Define, but do not evaluate e1 here.
	Expr(Name Expr(e2)); // Evaluate e1 here.
);
Show(e3);

Eval(Eval Expr(dt << New Script("Test", Expr(Name Expr(e3)))));

jthi_0-1742833430942.png

 

-Jarmo
robot
Level VI


Re: Insert a Expr() object into another script as an unevaluated Expr() object to be used later?

Very clever!  Thanks.