- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Expression Handling in JMP: Tips and Trapdoors
Collection of useful resources in the web:
- There is a wonderful lecture by @joseph_morgan in the Discovery Summit Series:Using JSL to Develop Efficient, Robust Applications (EU 2018 415)
Joseph explains the secrets and possibilities of Expression Handling in JSL - and the trapdoors associated with the functionality.
The lecture is based on the content of Expression Handling Functions: Part I - Unraveling the Expr(), NameExpr(), Eval(), ... Conundrum - Writing JSL code dynamically by @Jasean
(step-by-step guide through Universal Tricks #1 & #2, see below) - The Difference between Strings and Expressions - in 50 lines:
reply to a community post by @Craige_Hales - Nice Course with many application cases: Session 9: Advanced JSL , @jthi
- further info can be found in the Scripting Guide: advanced-expressions-macros-and-lists
Basics
internal:
#062 - expression handling in JSL
#092 - expression handling
1 | don't evaluate the expression (2+1), just store it in the variable x | x= Expr(2+1) |
2 | get the expression which is stored in x | Name Expr(x) |
3 | force evaluation | Eval(myexpr) |
4 | evaluate xyz and replace Expr(xyz) with the return value | Eval Expr( ... Expr(xyz)) |
*) NB: in 1 and 4, it's the same function "Expr(...)" - but with the opposite effect:
In 1, the content of Expr doesn't get evaluated, in 4 JUST the content of Expr gets evaluated
3 Universal Tricks
1 | pre-evaluate parts of an expression via Eval Expr() ... then evaluate the expression via Eval() solves 90%, (with option 2: 99%) of all issues | Eval(Eval Expr ( ... Exp(eval 1st) ...)) option 2: Eval(Eval Expr ( ... Exp(Name Expr( )) ...)) |
2 | Solves the same 99% like # 1 - option 2 | Eval(substitute(Expr(), Expr(), Name Expr() )) |
3 | ultimate trick for column references ( @jthi, e.g. Session 9: Advanced JSL @33min ) | Name Expr(as column("column name" or :column)) |
NB:
Some functions evaluate their arguments, some don't, some evaluate some of their arguments - there are functions like head() which evaluate their arguments to a certain degree: Does Head evaluate its argument? - and others evaluate their argument but if it's a single variable, they behave like Name Expr(): Exceptions are the utilities Show, Write, and Print ...
Unfortunately, most of these details are not available for the users. The users have to guess.
Here is a wish for JSL editor to help the users by showing this information interactively: Advanced syntax highlighting in JSL Editor - does the function evaluate it's argument?
-> If you want to get this automatic support, please follow the link and vote!
Examples from the community:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Expression Handling in JMP: Tipps and Trapdoors
Hi @hogi ,
Thanks for consolidating this information and bringing a lot of this information together. The talk sounds really informative.
I do like how you can do things several different ways in JMP and in JSL, but sometimes there are too many different ways that are very specific to the case at hand, and this can become somewhat cumbersome when trying to make code that is generic and able to handle many different scenarios.
Thanks!,
DS
This post originally written in German and has been translated for your convenience. When you reply, it will also be translated back to German.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Expression Handling in JMP: Tipps and Trapdoors
If you don't use the tricks:
Oops - I lost my data table ... |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Expression Handling in JMP: Tipps and Trapdoors
JSL and variables - 3 issue you should be aware off when writing JSL code.
Different issues, always the same solution : )
the solution?
-> just read the main post.
c= 5;
col = Name Expr(:height);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = graph Builder(); framebox = report(gb)[FrameBox(1)];
// issues with variables in a message
// all 3 of them look quite innocent
// but none of them will survive a restart
New Column ("rescaled", Formula (c * :height));
dt << New Column ("rescaled", Formula (5 * col));
framebox << Add Graphics Script(Y Function( c * x, x ) );
// no issue here:
dt << concatenate(dt);
dt << new column(c, formula(3));
One could think: don't ever use a variable in a message!
But this goes way too far - the last 2 examples don't have an issue.