For example, consider the following code
f[x_] := (Print["evaluated f"]; workWith[x]);
We use it, then f evaluates:
f[x] (* evaluated f, workWith[x] *)
When we use f in the assignment, f does not evaluate:
f[x] = 1 (* 1 *)
Is it possible to construct a pattern that will detect cases when f[x] is used unevaluated like in the Set command? For example, one could do
f /: Set[f[x_], rhs___] := somework when f is not evaluated
but that would only work specifically for the Set command. Is there a way to make it more generic?, for example like this
HeldExpression[f[x_]] := somework when f is not evaluated
would be great but, of course, HeldExpression does not exist.
I realized that
f /: HoldPattern[_[___,f[x_],___]] := work with f when used
actually triggers even if f is used in the context of the Set command, but it does not discriminate between to be evaluated (y=f[x];) and not to be evaluated (f[x]=1;) scenarios.