Re: why does DownValues not return all downvalues for a
- To: mathgroup at smc.vnet.net
- Subject: [mg99413] Re: [mg99369] why does DownValues not return all downvalues for a
- From: Michael <michael2718 at gmail.com>
- Date: Tue, 5 May 2009 05:41:59 -0400 (EDT)
- References: <200905040959.FAA22619@smc.vnet.net>
On Mon, May 4, 2009 at 7:01 AM, Bob Hanlon <hanlonr at cox.net> wrote: > v = DeleteCases[ > ToExpression[Names["*Values"]], > SingularValues]; > > g["x"]["y"] = 1; > > {#, #[g]} & /@ v It appears that the function that returns what I need is called "SubValues"= : In[9]:= SubValues[g] Out[9]= {HoldPattern[g["x"]["y"]] :> 1} This function doesn't appear to be documented very well (it doesn't have it's own page), but it is mentioned in passing a couple of places. Thanks for the help! > > Bob Hanlon Michael > > ---- Michael <michael2718 at gmail.com> wrote: > > ============= > I'm trying to get the functionality of "associative arrays" or "alist" > or "hash tables" to work in Mathematica. However I'm seeing a quirk > and I wonder if anybody can explain what is going on or suggest a > better approach? > > I can define a simple associate array like so: > f["red"]=1; > f["blue"]=2; > ... > If all my parameters are strings, then I can find the "keys" to my > alist with the following function: > StringKeys[y_] := DownValues[y] /. {( _[y[str_String]] :> _) -> str}; > SetAttributes[StringKeys, HoldFirst]; > > In[141]:= StringKeys[f] > > Out[141]= {"blue", "red"} > > However, if I try to define a more complex alist, I cannot find any > way to retrieve the definition! > > In[142]:= g["x"]["y"] = 1; > > In[143]:= DownValues[g] > > Out[143]= {} > > In[144]:= UpValues[g] > > Out[144]= {} > > > Any ideas? > > Thanks, > > Michael
- References:
- why does DownValues not return all downvalues for a symbol?
- From: Michael <michael2718@gmail.com>
- why does DownValues not return all downvalues for a symbol?