- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Insert a Expr() object into another script as an unevaluated Expr() object to be used later?
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 ) ) ) ) );
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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)))));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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:
the last trick:
mark the Eval Expr(...) inside an Eval() and "run" it to check if the expression is what you expect:
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:
[e1 is just defined within the here namespace of the script]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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 ) ) ) ) );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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)))));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Insert a Expr() object into another script as an unevaluated Expr() object to be used later?
Very clever! Thanks.