MathGroup Archive 2007

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

Search the Archive

Re: Get list of function variables?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83342] Re: Get list of function variables?
  • From: Peter Pein <petsie at dordos.net>
  • Date: Sat, 17 Nov 2007 05:39:11 -0500 (EST)
  • References: <fhjs5v$4t3$1@smc.vnet.net>

Jason Quinn schrieb:
> This seems simple but how do I get the arguments to an arbitrary
> function? Ideally something like getVariables[f] that just accepts the
> function name as its argument.
> 
> If I have f[x_,y_]:=a*x^2+b*y^2,  getVariables[f] should return {x,y}
> If I have g[n_,m_]:=a*n^2+b*m^2, getVariables[g] should return {n,m}
> If I have h[w_,x_,y_,z_]:=A*w*x*y*z+B, getVariables[h] should return
> {w,x,y,z}
> 
> Thanks for any suggestions,
> Jason
> 

Hi Jason,

with

f[x_, y_] := a*x^2 + b*y^2;
g[n_, m_] := a*n^2 + b*m^2;
h[w_, x_, y_, z_] := A*w*x*y*z + B;

and

getVariables :=
  Part[DownValues[#] /. # -> List, 1, 1, 1, All, 1] &

you'll get:

getVariables /@ {f, g, h}

{{x, y}, {n, m}, {w, x, y, z}}

this will not work for kernel functions (First[], Sin[] etc.).

Peter


  • Prev by Date: Re: SoundNote does not accept "H"
  • Next by Date: Re: Default value for Dynamic InputField
  • Previous by thread: Re: Get list of function variables?
  • Next by thread: Re: Get list of function variables?