1
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?

Alan
  • 13,686
  • 19
  • 38

1 Answers1

2

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:

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
  • Thanks. I forgot that ValueQ has the HoldFirst attribute, which should have been obvious. – Alan Jun 09 '17 at 17:58