I want to generate some expressions. The expression is not evaluated expect some parts will evaluate first.

A simple example is Defer[1+1+1] and in this expression I need the last puls operation is evaluated. Some thing like Defer[1+ Evaluate[1+1]]. However this do not work and return 1+Evaluate[1+1]. The Evaluate is shadowed by Defer.

How can I get 1+2 as the result.

I will use this method to generate WhenEvent[ ] in NDSolve.

  • 3
    $\begingroup$ Evaluate work on the first level of a held expression. Here it is deeper. you can use With or something like Defer[1+#]&[1+1] $\endgroup$
    – Kuba
    Jun 1, 2016 at 5:40
  • $\begingroup$ Maybe you'll find deepEvaluate useful. $\endgroup$
    – jkuczm
    Jun 1, 2016 at 16:41


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.