# If ValueQ is buggy, what alternative is there?

The function ValueQ has been irritating me for a while. I can't find its use for anything. Inspect the following:

a;
b = 1;
c = "c";
DetermineIfValueAssigned[x___] := Table[ValueQ[{x}[[i]]], {i, Length[{x}]}];
DetermineIfValueAssigned[a, b, c]


Expected Output:

{False,True,True}


Instead, returns Output:

{True,True,True}


However, ValueQ[a] by itself does return the expected False.

What's going on here that can be re-implemented to obtained the wished results?

• While ValueQ can be tricky it looks like your function construction is the problem here.
– Kuba
Mar 27, 2018 at 10:37
• @Kuba How so? Consider this other example: {InputField[Dynamic[x], String, ContinuousAction -> True], Dynamic@ValueQ[x]}. Doesn't work neither. Mar 27, 2018 at 10:39
• {x}[[i]] - this is rather expected to change, isn't it?
– Kuba
Mar 27, 2018 at 10:40
• Please do not use the bugs tag unless any behavior you've observed has been confirmed to be a bug. Mar 27, 2018 at 10:40
• @Kuba ValueQ\@{a,b,c} is not allowed... Mar 27, 2018 at 10:41

If ValueQ[a] returns expected output and your function does not, how come have you decided to blame ValueQ?

There are two problems.

You don't prevent b or c from evaluation so before they get to ValueQ they are already evaluated to 1 and "c".

You need to be more careful with what you put in ValueQ. If you have ValueQ[{x}[[i]]] it will clearly change to anything that is in {x}.

a;
b = 1;
c = "c";

foo // Attributes = {HoldAll, Listable};
foo[x___] := foo[{x}]
foo[x_] := ValueQ[x]

foo[a, b, c]


{False, True, True}

Listable may not fit your general use case well so here is a way without it:

foo // ClearAll
foo // Attributes = {HoldAll};
foo[x_, rest__] := Flatten@{ValueQ[x], foo[rest]}
foo[x_] := {ValueQ[x]}