cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
hogi
Level XII

Expression Handling in JMP: Tipps and Trapdoors

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 it.
The lecture is based on the content of Expression Handling Functions: Part I - Unraveling the Expr(), NameExpr(), Eval(), ... Conundrum 

further info can be found in the Scripting Guide: advanced-expressions-macros-and-lists 

 

 

Basics
internal: #062 - expression handling in JSL

1Protect an Expression from being evaluated, just store itx= Expr(2+1)
2get the expression stored in my variable nameName Expr(my variable name)
3force evaluationEval(myexpr)
4to force pre-evaluation of Expr() *)Eval Expr( ... Expr())

*) the same "Expr()" as in 1 - but with a different application: Eval Expr will search and pre-evaluate it

 

 

 

3 Universal Tricks

1pre-evaluate an Expression - the solution for 90% of the issues
with this extension you will reach 99% →
Eval(Eval Expr ( ... Exp(eval 1st) ...))
maybe:
Eval(Eval Expr ( ... Exp(Name Expr(  )) ...))
2The same 99%:Eval(substitute(Expr(), Expr(), Name Expr() ))
3ultimate 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 - and there are functions like head which evaluate their arguments to a certain degree: Does Head evaluate its argument? 

Unfortunately, this info is not publicly available - but it could be: Advanced syntax highlighting in JSL Editor - does the function evaluate it's argument? 

 

 

 

Examples:

TopicLinksDetails

Column() vs.

As column() vs.

name()

Why do these ways of referencing columns give different results?How to replace :column_name with variable in JMP JSL?Column() vs As Column() vs datable:column vs dt:As name("column") 

the universal syntax to reference a column is :column. But often, it's tricky to get the   ":column" right ...

Column references in column formulas

Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute

Trying to create a column and fill it with a formula but I get an error.

Use expr() to replace variable column names in a formulaAdding Formula Columns based on Column Name ListCreating a formula column from a list ( JSL )Need help with expressions, column references, formulas and column renamingCreate new columns by loop formula calculation with specific column namesJSL to create formula column with variable column names Column name from string 

Script concatenate columns 

Using Expr() and Eval() with variables name inside a loopUse column variable in IF expression

JSL: Creating formula using a variable column name

Using variables to create formula columnscreating formula using existing column names 

Iterating Columns 

define the column via 

col = Name Expr(As Column(colname))

and insert it with Eval(Substitute())

Alternatives:

As Column (Expr(colname))

with Eval(Eval Expr())

or

Expr(Name Expr(AsColumn(dt, colname)))

with Eval(Eval Expr())
...

Column references in platform calls and messages

JSL help proper referencing of a columnRun a Platform without Knowing the Number or Names of Columns

Distribution using column list 

JSL: help properly referencing a data table column for Distribution platform 

use

Name Expr(As Column(colname))

with Eval(substitute())


... or if you have issues with a column list,  just add eval() or  evallist()in the column() argument 

use a column reference in a function call

Column reference in custom functionCustom Function - how to reference the column

- wrap the column with
 Name Expr()

- use a list

construct an expression 

Can you construct this without writing expression as a string?Run a Platform without Knowing the Number or Names of ColumnsUsing list of columns in formulas

How to script an aggregate column from a variable list of column references 

- start with an empty draft and fill it via insert into(draft, arguments)

- use substitute

- create a list, and substitute list with another JSL symbol

further workarounds via Expression handling

Exclude rows in Col Quantile Calculation

prevent inappropriate caching in Col Quantile by using an expression.

From version to version, less expression handling is needed to make things worklink? 
2 REPLIES 2
SDF1
Super User

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

hogi
Level XII

Re: Expression Handling in JMP: Tipps and Trapdoors

If you don't use the tricks:

Oops - I lost my data table ...