Re: ValueQ
- To: mathgroup at smc.vnet.net
- Subject: [mg34339] Re: ValueQ
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Thu, 16 May 2002 05:08:19 -0400 (EDT)
- References: <abt3i0$naf$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Rainer,
ValueQ[expr] gives False only if expr would not change if it were to be
entered as Mathematica input.
ValueQ has the attributes HoldAll, so ValueQ[expr] works on the unevaluated
expr.
These explain your examples.
A simpler way for dealing with your problem is
Table[With[{i=i},ValueQ[a[i]]], {i, 1, 2}]
{True,False}
For example, the first element of the list is generated by
Local definition, i=1;
With[{i=i},ValueQ[a[i]]] -->
With[{i=1},ValueQ[a[i]]]-->
ValueQ[a[1]]]-->
True
the second entry is generated by
Local definition, i=2;
With[{i=i},ValueQ[a[i]]] -->
With[{i=2},ValueQ[a[i]]]-->
ValueQ[a[2]]]-->
False
The important point here is that With inserts values, in a similar way to
ReplaceAll.
--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"rainer" <rainer.gruber at gmx.at> wrote in message
news:abt3i0$naf$1 at smc.vnet.net...
> Hi,
>
> I#m searching for a simple workaround of the following behaviour.
>
> For the symbol 'a' I've defined
>
> In[1]:=
> a[1] = 2;
>
> When I evaluate ValueQ for a defined and for not a defined expression I
> get what I expect:
>
> In[3]:=
> ValueQ[a[1]]
> Out[3]=
> True
>
> In[4]:=
> ValueQ[a[2]]
> Out[4]=
> False
>
> But when I evaluate ValueQ e. g. within a Table I always get True:
>
> In[5]:=
> Table[ValueQ[a[i]], {i, 1, 2}]
> Out[5]=
> {True, True}
>
> The 2nd 'True' is because 'a[i]' is not equal to 'a[2]'. A first
> solution to get the expected result is
>
> In[6]:=
> Table[ToExpression@("ValueQ[a[" <> ToString[i] <> "]]"), {i, 1, 2}]
> Out[6]=
> {True, False}
>
> Does anybody know something better?
>
> Rainer Gruber
> JOHANNES KEPLER UNIVERSITY LINZ
> Institute of Experimental Physics
> Atomic Physics and Surface Science
>
>