MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: List of patterns for which a function is defined?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24425] 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:23 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Here is a simple 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
-- 
Andrzej Kozlowski
Toyama International University, JAPAN

For Mathematica related links and resources try:
<http://www.sstreams.com/Mathematica/>



on 7/13/00 12:13 PM, Roger Wilson at roger.wilson at nomura.co.uk wrote:

> 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?
> 
> Roger.
> 
> ---------------------------------------------------------------------
> Roger Wilson, Quantitative Analysis Group | roger.wilson at nomura.co.uk
> <mailto:roger.wilson at nomura.co.uk>
> Nomura International plc, Nomura House | Phone: +44 020 7521 2373
> 1 St. Martin's-le-Grand, London EC1A 4NP | Fax:   +44 020 7521 3676
> ---------------------------------------------------------------------
> Any views or opinions presented are solely those
> of the author and do not necessarily represent those
> of Nomura or any of its affiliates.
> Nomura International PLC is a member of the
> London Stock Exchange and is regulated by The Securities and
> Futures Authority.
> ---------------------------------------------------------------------
> 
> 
> 
> 




  • Prev by Date: Re: FixedPoint vs. FixedPointList
  • Next by Date: Re: strange Integrate result
  • Previous by thread: Re: List of patterns for which a function is defined?
  • Next by thread: Usage Messages Useful for the SHIFT+CONTROL+K Feature