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