ClearAll[f1, f2]
f1[x_] := x*x
f2 = #*# &;
This produces the expected results:
ValueQ[f1] (* False *)
ValueQ[f2] (* True *)
I find this unexpected:
ValueQ /@ {f1, f2} (* {False,False} *)
How can I understand the difference?
ClearAll[f1, f2]
f1[x_] := x*x
f2 = #*# &;
This produces the expected results:
ValueQ[f1] (* False *)
ValueQ[f2] (* True *)
I find this unexpected:
ValueQ /@ {f1, f2} (* {False,False} *)
How can I understand the difference?
In ValueQ /@ {f1, f2} the expression {f1, f2} is evaluated before ValueQ is applied, therefore ValueQ never "sees" f2, only its value #*# & which itself does not have a value.
It is critical to understand the standard evaluation order in Mathematica or you shall be chasing many problems or surprises of this nature. Recommended reading:
Operator precedence is also critical unless you exclusively use bracketed notation; see:
ValueQ has the HoldFirst attribute, which should have been obvious.
– Alan
Jun 09 '17 at 17:58
ValueQ /@ Unevaluated[{f1, f2}]. – ilian Jun 09 '17 at 16:14