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 +y
Wonderful!
... 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 anymore
Dangerous ...
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()