RE: Re: RE: Re: ValueQ
- To: mathgroup at smc.vnet.net
- Subject: [mg34430] RE: [mg34411] Re: [mg34376] RE: [mg34340] Re: ValueQ
- From: "DrBob" <majort at cox-internet.com>
- Date: Sun, 19 May 2002 04:14:56 -0400 (EDT)
- Reply-to: <drbob at bigfoot.com>
- Sender: owner-wri-mathgroup at wolfram.com
OK, but that explanation of SubValues doesn't EXPLAIN anything. An equal number of words COULD do the job, but those words do not. The Mathematica Book leaves this one out of its index, and it isn't discussed on pages that discuss DownValues... as it certainly should be, since they're two sides of the same coin. I discovered by trial and error that DownValues records that f[1]:=1 but SubValues records that f[2]=2. (SetDelayed versus Set) Both are returned in the same form involving RuleDelayed. I suppose I shouldn't be irritated that not everything, in such a huge system, is well documented. Bobby -----Original Message----- From: Andrzej Kozlowski [mailto:andrzej at platon.c.u-tokyo.ac.jp] To: mathgroup at smc.vnet.net Subject: [mg34430] Re: [mg34411] Re: [mg34376] RE: [mg34340] Re: ValueQ Just evaluate: ?*Values And you will be lead to all of them. On Saturday, May 18, 2002, at 08:11 PM, DrBob wrote: > Uh oh... where do I find explanations for OwnValue and SubValue? > > Bobby Treat > > -----Original Message----- > From: Andrzej Kozlowski [mailto:andrzej at platon.c.u-tokyo.ac.jp] To: mathgroup at smc.vnet.net > Sent: Saturday, May 18, 2002 2:52 AM > Subject: [mg34430] [mg34411] Re: [mg34376] RE: [mg34340] Re: ValueQ > > The purpose of ValueQ is to check if a symbol is a "value", which means > not just a DownVlaue, but also OwnVlaue, SubValue and so on, e.g.: > > In[1]:= > a/:f[a]=2; > > In[2]:= > f[b]=3; > > In[3]:= > c=5; > > In[4]:= > ReleaseHold[Map[ValueQ,Hold[{f[a],f[b],f[c],c,d,f[d]}],{2}]] > > Out[4]= > {True,True,True,True,False,False} > Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ > > > On Friday, May 17, 2002, at 07:31 PM, DrBob wrote: > >> Here's a more direct method: >> >> Position[DownValues[a], HoldPattern[a[#]]] != {} & /@ {1, 2} >> >> {True,False} >> >> This is what I'd have expected ValueQ to do, if I hadn't seen the >> examples and read the fine print. >> >> Bobby >> >> -----Original Message----- >> From: Jens-Peer Kuska [mailto:kuska at informatik.uni-leipzig.de] To: mathgroup at smc.vnet.net >> Subject: [mg34430] [mg34411] [mg34376] [mg34340] Re: ValueQ >> >> Hi, >> >> Table[ ValueQ @@ (Hold[a[ii]] /. ii -> i), {i, 1, 2}] >> >> Regards >> Jens >> >> rainer wrote: >>> >>> 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 >> >> >> >> >> >> > > > >