I am a big fan of Eval(Substitute(Expr(...), Expr(..), Expr(.)))
: )
The only disadvantage: the Expr(...), Expr(..), Expr(.)
... which brought me to the idea of subst() - substitute() 2.0 ... a function which doesn't evaluate it's arguments.
While playing around with Expression Handling, I noticed that the desired logic for Subst() is quite close to the one of Extract Expr(): no need to use Expr(), and Name Expr() is applied wherever it is possible:
Names Default to here(1);
// direct mode, no Expr necessary
Extract Expr(x^2 + 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 +yWonderful!
... till:
Extract Expr(cc * d , cc); // -> cc
cc=Expr(x^2);
Extract Expr(cc * d, cc);// looks up cc = x^2 , so doesn't find cc in cc * d anymoreDangerous ...
after defining cc as a symbol with a name expr, is it still possible to use c "literally" in Extract Expr ?
Extract Expr(cc * d , Expr(cc)); // doesn't work
Extract Expr(Expr(cc) , Expr(cc)); // finds Expr(cc)
Extract Expr(cc , Name Expr(Expr(cc))); // -> empty
Extract Expr(Name Expr(Expr(cc)) , Name Expr(Expr(cc))); // finds Name Expr(Expr(cc)), argh!
even:
cc=Expr(x^2);
clear symbols(cc);
Extract Expr(cc * d , cc); //-> empty()
Why would you use same variable name in multiple places like that?
Delete Symbols() and Clear Symbols() are not same
Names Default To Here(1);
cc = Expr(x ^ 2);
Delete Symbols(cc);
Extract Expr(cc * d, cc);
maybe:
use a custom function as a wrapper for Extract Expr
Names default to here(1);
dummy=Function ({expression, pattern},
Extract Expr(expression, pattern);
);
cc = Expr(x^2);
dummy( Expr(cc+d), Expr(cc)); // -> cc
Is there something you are looking answers for? Also have you read Scripting Guide about expressions Scripting Guide > Programming Methods > Advanced Expressions, Macros, and Lists - Advanced Expressio... and especially the parts how they get evaluated?
On the linked page I did not find further info about ExtractExpr ()
@jthi wrote:
Is there something you are looking answers for?
how to make sure JMP searches for cc in the expression cc * d ?
... even if cc is used as a name for another expression, like of x^2.
Extract Expr(cc * d , cc); // -> cc
cc=Expr(x^2);
Extract Expr(cc * d, cc);// looks up cc = x^2 , so doesn't find cc in cc * d anymore
and more general:
A custom function ALWAYS evaluates its arguments - and via Expr() one can prevent it from doing so.
Extract Expr ALWAYS retrieves the unevaluated expression behind a name (if there is one) before using it - can the user prevent it from doing so?
Platform commands often get disturbed when names are used as arguments - and Eval might fix the issue.
How many categories of handling arguments are there in JSL in total? Is there any red line behind?
Why would you use same variable name in multiple places like that?
Delete Symbols() and Clear Symbols() are not same
Names Default To Here(1);
cc = Expr(x ^ 2);
Delete Symbols(cc);
Extract Expr(cc * d, cc);
Thanks for the link.