Consider the following


We expect False and get it. Now consider

ValueQ[jd /. {foo -> Unique[]}]

which yields True. But

jd /. {foo -> Unique[]}

is just jd and has no value defined. What's going on here?

  • $\begingroup$ ValueQ[] is a funny beast. Try {ValueQ@E, ValueQ@Sin@E, ValueQ@Pi, ValueQ@Sin@Pi, ValueQ@N@Pi} :) $\endgroup$ – Dr. belisarius Dec 25 '13 at 19:10
  • 3
    $\begingroup$ some related questions on ValueQ $\endgroup$ – rm -rf Dec 25 '13 at 19:18
  • 6
    $\begingroup$ According to the doc, "ValueQ gives False only if expr would not change if it were to be entered as Mathematica input.", so the Value in ValueQ does not mean numerical value I think. $\endgroup$ – Silvia Dec 25 '13 at 19:31
  • 1
    $\begingroup$ See the definition for yourself: ClearAttributes[ValueQ, Protected]; ClearAttributes[ValueQ, ReadProtected]; ValueQ // Information; DownValues[ValueQ][[1]] /. {SystemDumps -> s, SystemDumph -> h} $\endgroup$ – Jacob Akkerboom Dec 25 '13 at 21:54
  • 1
    $\begingroup$ So in your case we have (both give True): ! Hold[Evaluate[jd /. {foo -> Unique[]}]] === Hold[jd /. {foo -> Unique[]}], as ! Hold[Evaluate[jd]] === Hold[jd /. {foo -> Unique[]}] $\endgroup$ – Jacob Akkerboom Dec 25 '13 at 22:03

If, say, f has the HoldAll attribute, you should not assume f[2] to be the same as f[1+1]. ValueQ has such attribute.

ValueQ tests whether the expression changes upon evaluation.

jd /. {foo -> Unique[]} evaluates to jd which is different from the original unevaluated form jd /. {foo -> Unique[]}. Therefore, ValueQ[jd /. {foo -> Unique[]}] gives True


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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