Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actually, the ValueQ function is not innocent, since it leaks evaluation for code with side effects. Examples:</p> <pre><code>ClearAll[f, g]; f[x_] := Print[x]; g[x_][0] := Print[x]; {ValueQ[f[1]],ValueQ[g[2][0]]} </code></pre> <p>If you remove the ReadProtected Attribute of ValueQ and look at the code, you will see why - the code is very simplistic and does a decent job for OwnValues only. Here is a more complex version which I developed to avoid this problem (you can test that, at least for the examples above, it does not leak evaluation):</p> <pre><code>ClearAll[symbolicHead]; SetAttributes[symbolicHead, HoldAllComplete]; symbolicHead[f_Symbol[___]] := f; symbolicHead[f_[___]] := symbolicHead[f]; symbolicHead[f_] := Head[Unevaluated[f]]; ClearAll[partialEval]; SetAttributes[partialEval, HoldAllComplete]; partialEval[a_Symbol] /; OwnValues[a] =!= {} := Unevaluated[partialEval[a]] /. OwnValues[a]; partialEval[a : f_Symbol[___]] /; DownValues[f] =!= {} := With[{dv = DownValues[f]}, With[{eval = Hold[partialEval[a]] /. dv}, ReleaseHold[eval] /; (First[Extract[eval, {{1, 1}}, HoldComplete]] =!= HoldComplete[a])]]; partialEval[a_] := With[{sub = SubValues[Evaluate[symbolicHead[a]]]}, With[{eval = Hold[partialEval[a]] /. sub}, ReleaseHold[eval] /; (First[Extract[eval, {{1, 1}}, HoldComplete]] =!= HoldComplete[a])]]; ClearAll[valueQ]; SetAttributes[valueQ, HoldAllComplete]; valueQ[expr_] := partialEval[expr] =!= Unevaluated[partialEval[expr]]; </code></pre> <p>This is not complete either, since it does not account for UpValues, NValues, and FormatValues, but this seems to be enough for your stated needs, and also, rules for these three extra cases can perhaps also be added along the same lines as above. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload