# Behavior of ValueQ inside a function

The following code

Cases[Function[{x}, x + 1], a_?ValueQ :> Hold[a], ∞, Heads -> True]


unexpectedly returns

{Hold[x + 1]}

According to the manual, "ValueQ[expr] gives True if a value has been defined for expr, and gives False otherwise."

In the example above, what is the expression that was assigned the value x+1?

-
You can use Trace to see that ValueQ[expr] is in fact ! Hold[Evaluate[expr]] === Hold[expr], and since Evaluate[x+1] is 1+x it passes the test. It is strange to me, maybe someone else can confirm it's desired behaviour or a bug. –  Kuba Nov 7 '13 at 13:33
I recommend reading this discussion and come comments / chat session linked there. –  Leonid Shifrin Nov 7 '13 at 14:29

The definition for ValueQ says

gives True if a value has been defined for expr, and gives False otherwise.

So in this context you result is very strange. But later in Details section there is more conservative statement:

ValueQ gives False only if expr would not change if it were to be entered as Mathematica input.

So even if it does look strange, almost a bug, it fits the description because Mathematica uses different order, as default, than traditional.

x + 1

1 + x

-