I'm looking for a function that applies the following behavior to an expression:
-When the expression is given as the full input, or as part of a function that cannot be evaluated, it remains in unevaluated form. -When the expression is used for a function, it is evaluated.
Defer[]
won't evaluate it in a function. Unevaluated[]
leaves itself in evaluated when used directly as output.
Essentially, I need a function F[]
that will output the following:
F[1-1/2]
outputs1-1/2
, NOT1/2
Times[F[1-1/2],5]
outputs5/2
, NOT(1-1/2)5
Times[F[1-1/2],x]
outputs(1-1/2)x
, NOTx/2
If the solution only works for a specific internal expression, that works, because I only need this for one function.
UpValues
andHoldForm
. $\endgroup$ – Verbeia Jan 10 '13 at 5:06Times
your actual "specific internal" function? Your third requirement is likely going to require knowledge of that function and special handing. $\endgroup$ – Mr.Wizard♦ Jan 11 '13 at 5:49