Re: List of patterns for which a function is defined?
- To: mathgroup at smc.vnet.net
- Subject: [mg24435] Re: [mg24378] List of patterns for which a function is defined?
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Tue, 18 Jul 2000 00:58:34 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I failed to notice a weakness in my previous reply in that
some of the arguments maybe strings (in your case "cat") and instead of the
string "cat" my function returnsthe symbol cat. This problem can me fixed
as follows:
In[1]:=
ListOfPatternsDefined[a_] :=
Map[If[Head[a[#]] === a, ToString[#], #] &,
Cases[ToHeldExpression[ToString[Definition[a]]], a[x_] -> x, Infinity]]
In[2]:=
a[1] = 4; a[2] = 5; a["cat"] = "sam";
In[3]:=
ListOfPatternsDefined[a]
Out[3]=
{1, 2, "cat"}
Andrzej
on 7/14/00 9:43 AM, Andrzej Kozlowski at andrzej at tuins.ac.jp wrote:
> Here is a function that will accomplish this at least in your case and
> similar ones
>
> In[1]:=
> ListOfPatternsDefined[a_] :=
> Cases[ToHeldExpression[ToString[Definition[a]]], a[x_] -> x, Infinity]
>
> In[2]:=
> a[1] = 4; a[2] = 5; a["cat"] = "sam";
>
> In[3]:=
> ListOfPatternsDefined[a]
>
> Out[3]=
> {1, 2, cat}
>
>
> Andrzej