Skip to main content
3 of 4
added 90 characters in body
PlatoManiac
  • 15k
  • 2
  • 44
  • 76

Probably irrelevant but I thought you have some function defined in the Global` context and you want to get the list of its variables. If that is the case I came up with this messy solution.

Suppose you have defined a function like the following somewhere in a notebook and the definition for the symbol fun is available to the kernel as well as not Protected. I am defining the following example function using Module but one can also use Block.

Clear[f]; fun[x_, y_, z_] := Module[{val}, val = RandomReal[1, 3]; val . {x, y, z} ]; 

{x,y,z}

Then you can get the arguments of fun using the following

((DownValues[fun])[[1]] /. RuleDelayed[HoldPattern[a___],b_] :> (Extract[a, 1, Hold] /. Hold[c_[vars___]] :> List@vars)) 

{x_, y_, z_}

If you want you can easily convert those pattern into Symbol using First /@%.

PlatoManiac
  • 15k
  • 2
  • 44
  • 76