Re: List of patterns for which a function is defined?
- To: mathgroup at smc.vnet.net
- Subject: [mg24447] Re: [mg24378] List of patterns for which a function is defined?
- From: BobHanlon at aol.com
- Date: Tue, 18 Jul 2000 00:58:49 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 7/12/2000 11:46:55 PM, roger.wilson at nomura.co.uk writes:
>I have a function b which I define explicitly for a set of input values.
>
>a[1]=4; a[2]=5; a["cat"]="sam";
>
>If I type ??a I get the usual listing of the definition of a but how do
>I
>get a list of the values or patterns for which a is defined?
>
>ListOfPatternsDefined[a]
>{1,2,"cat"}
>
>In python this would be a.keys() but in Mathematica I'm stuck?
>
>Any ideas?
>
a[1] = 4; a[2] = 5; a["cat"] = "sam"; a["2"] = "five";
ListOfPatternsDefined[a_Symbol] :=
ReleaseHold[(First /@ DownValues[a]) /. a[x_] -> x]
ListOfPatternsDefined[a]
{1, 2, "2", "cat"}
a /@ %
{4, 5, "five", "sam"}
Bob Hanlon