0
$\begingroup$

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?

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

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]}
$\endgroup$

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.