MathGroup Archive 2010

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

Search the Archive

Re: Obtaining information about function definitions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114809] Re: Obtaining information about function definitions
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Fri, 17 Dec 2010 06:21:58 -0500 (EST)
  • References: <ief737$pqn$1@smc.vnet.net>

Am 17.12.2010 09:30, schrieb ntg:
> Suppose I have defined a set of functions associated with symbol f and
> indexed by strings, for example
> 
> f["abc"][x_] := 1;
> f["def"][x_] := 2;
> f["ghi"][x_] := 3;
> ....
> 
> I would like to write a program that defines a new set of functions
> associated with g and indexed by the same strings.
> 
> How can I obtain a list of all the strings that have been used as
> indexes of f? Both Information[f] and Definition[f] result in output
> that "shows" me the information I seek. But I can't access and
> manipulate that information. There must be a way to do this. Can
> anyone help?

This should work for your example:

Cases[SubValues[f], _[_[f[s_String][_]], _] :> s]

SubValues is unfortunatly not well documented, but see the documentation
for DownValues, which gives you most of the Information needed to guess
what SubValues are.

If you have defined other patterns for f, like this:

f[args___] := Print[args];

you might need to be more careful and use a more complicated pattern
like e.g. this:

Cases[SubValues[f],
 Verbatim[RuleDelayed][
   Verbatim[HoldPattern][HoldPattern[f[s_String][_]]], _] :> s
 ]


  • Prev by Date: Re: How can I perform Matrix comparison? Can any one with kindness help
  • Next by Date: Re: Wolfram Library Archive - kaput?
  • Previous by thread: Re: Obtaining information about function definitions
  • Next by thread: Re: Obtaining information about function definitions