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

subst() - substitute() 2.0

☐ 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? 

Substitute is a very powerful function for expression handling:

Using JSL to Develop Efficient, Robust Applications (EU 2018 415) 

A big disadvantage of Substitute: it evaluates it's arguments : (

Therefore, Expressions with Substitute() get quite lengthy and hard to read. Besides that, a new JSL scripter has to learn the correct syntax - nobody expects that all those Expr() are necessary.

 

Example:

Substitute( Expr( a + Sqrt( a ) ), Expr( a ), Expr( b ) )

 

What is the improvement you would like to see? 

A new function subst () which doesn't evaluate it's arguments. Then one can write :

Substitute( a + Sqrt( a ), a, b )

 

Why is this idea important? 

Subst() and Eval(Subst()) will be used millions of times - and each time a JSL scripter will be happy that you implemented it!

 

other wishes from hogi_2-1702196401638.png

 

3 Comments
hogi
Level XII

In most of the cases, the user will provide at least one of the arguments as a name -  with the idea that JMP looks up the name and uses the Name Expr instead of the name itself.

So, JMP should evaluate the arguments to a level (look up, take the Name Expr if available, don't evaluate further) where it's possible to write:

a=Expr(myExpr);
Subst(x+y, x, a) // result: myExpr + y

instead of 

a=Expr(myExpr);
Substitute(Expr(x+y), Expr(x), Name Expr(a)) // result: myExpr + y

.

And if a user wants to be sure that JMP uses the argument as it is (without resolving the  Name Expr.), he can write:

a=Expr(myExpr);
Subst(x+y, x, Expr(a)) // result: a + y  

 

hogi
Level XII

With other words:
 Subst()
... a Substitute() with the magic/easiness of Extract Expr()

 

 

clear symbols();
// direct mode, no Expr necessary
Extract Expr(x + y, x);// -> x
Extract Expr(x^2 + y, c);// no c in x^2 + y ->  empty

// Name Expr mode
c=Expr(x^2);
Extract Expr(x^2 + y , c);// looks up c = x^2, find "x^2"" in x^2 +y

 

unfortunately, what doesn't work (as easy as I wished):

c=Expr(x^2);
Extract Expr(c * d, Expr(c))

Extract Expr 

mia_stephens
Staff
Status changed to: Acknowledged

Thank you for the suggestion @hogi .