1
$\begingroup$

Is there a way to stop the evaluation of an expression when the result of that expression would depend on the value of a Symbol?

f[g[x_]] := 2
g[1] := 3

f[g[1]]
f[3]
f[g[x]]
2

Here I would like to halt the execution when it tries to apply g[1]-> 3 to g[x] and fails. Basically is there a way to make the evaluation of an expression and the replacement of its Symbols commutative?

$\endgroup$
3
$\begingroup$

Possibly you need only the functionality provided by the HoldFirst, HoldAll, or HoldRest attributes, e.g.

SetAttributes[f, HoldFirst]

f[g[1]]
f[3]
f[g[x]]
2

f[3]

2

If this doesn't do all that you want could you give more examples of the behavior you desire?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.