Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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
up vote 5 down vote accepted

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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