cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar

Contains for expressions

☐ cool new feature
☐ could help many users!

☐ removes something that feels like a „bug“

☑ nice to have

☐ nobody needs it

 

What inspired this wish list request? 

To check if a string is part of a larger string - and to get the exact position - one can use contains().

 

To check if an item is in a list - and to get the exact position -  one can use contains().

 

To check if an expression shows up in a long expression
... there is no function in JMP/JSL. Neither is there a function to get the position.

 

This is surprising. Because there is this cool 

Substitute(Expr(...), Exr(replace), Expr(with))

which needs to find out if an expression can be found in a main expression - and where it is.

 

What is the improvement you would like to see? 

Please provide a JSL function to check if an expression shows up in a long expression - and to get the position(s):

e.g. if it's the 5. argument of the 3rd argument of the 1st argument of the main expression, the function could return {{1,3,5}}.

If it finds the expression at several places, it could return all different matches. 

If it finds the expression - but cannot locate it exactly [because it's just part of an argument], it could return 1.

And if the expression is missing, it could return missing.

 

Why is this idea important? 

Contains(Expr(...), Expr(search)) will facilitate JSL scripting.
It's slightly related to another new feature, 🙏 Expression Indexing: read and write access

 

other wishes from hogi_2-1702196401638.png

3 Comments
hogi
Level XII

seems to work:

ContainsExpr=Function ({expression, pattern},
	tmp = Substitute(Name Expr(expression), Name Expr(pattern), Expr(.));
	not(Name Expr(tmp)==Name Expr(expression))
);

myExpression = Expr({a+b/(x-y),3} );
ContainsExpr( Name Expr(myExpression), Expr(X));
ContainsExpr( Name Expr(myExpression), Expr(c));
ContainsExpr( Name Expr(myExpression), Expr(3));
hogi
Level XII

or via Extract Expr:

ContainsExpr=Function ({expression, pattern},
Not(is empty(Extract Expr(expression, pattern)));
);

myExpression = Expr({a+b/(x-y),3} );
ContainsExpr( Name Expr(myExpression), Expr(X));
ContainsExpr( Name Expr(myExpression), Expr(c));
ContainsExpr( Name Expr(myExpression), Expr(3));

Too bad there is no setting for custom functions to NOT evaluate the argument, but just look it up - a magic  Extract Expr is capable of.
Without this possibility, maybe it's better to learn the Not(is empty(Extract Expr(
... instead of EVERY time having to wrap the arguments with Expr() to save them from getting evaluated.

hogi
Level XII

@Sarah-Sylvestre .
-> wish can be closed.