# Is there a way to create a warning when a subexpression is not evaluated? [closed]

Consider the following function:

notEvaluating[x_] :=
Module[{y},
If[x != $Failed, y = "not failed", y = "failed"]; y ];  notEvaluating[$Failed] returns, as expected "failed". notEvaluating[1] however returns y\$1234, because 1 !=$Failed isn't evaluated further, you need to use FailureQ instead.

Is there a way to get a warning when, as in this example, some expressions aren't evaluated completely? I imagine it could be pretty helpful for debugging.

edit: I suspect it's not easy to find a concise description of the desired behavior in Mathematica terms. But I guess a first approach would be, that a warning occurs, when the Head of the result of an expression is equal to the Head of the expression itself. Ideally ignoring things like Integer, that under no circumstances can be evaluated further.

• For your specific case you can give the If a third branch that is evaluated if the condition doesn't evaluate to True or False. Regarldess of that, it's an interesting question. However, could you clarify at what point you'd like to have the warning? When the inequality check doesn't evaluate, or when the If doesn't evalute? Commented Feb 9, 2017 at 13:56
• How does a general expression that has not evaluated look? In the polynomial x[1]^2 - 3 x[2]^3, has x[1] been evaluated completely? Are Ifs the only case you need to process, or can you have other things? Commented Feb 9, 2017 at 13:56
• Can you give a computable definition of what "expression is not evaluated completely" means? Until you can do that, this question is unanswerable. Commented Feb 9, 2017 at 14:26
• How close ValueQ is?
– Kuba
Commented Feb 9, 2017 at 14:59
• you can use =!= to guarantee the logical test will be either true or false. Commented Feb 9, 2017 at 15:31