# Halt the computation when it encounters a Symbol?

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?

## 1 Answer

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?