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 /@%
.
From the comments a more robust solution came out credit to Mr. Wizard.
Cases[ DownValues[fun], HoldPattern[fun][vars__] :> {vars}, -1 ] /.
Verbatim[Pattern][name_, _] :> name
Sequence @@ f[x, y, z]
? $\endgroup$