# Referring to arguments passed to function

Is there a way to get the arguments passed to a function? For example, I have the generic function f, then if I have

f[1,2]


I want to get {1,2}, and if I have

f[Sin[x],Cos[x],4,7]


I want to get {Sin[x],Cos[x],4,7}. Thanks!

• [Sin[x],Cos[x],4,7] is not a valid Mathematica expression. Maybe you can try Sequence @@ f[Sin[x], Cos[x], 4, 7] or f[Sin[x], Cos[x], 4, 7] /. f -> Sequence or List @@ f[Sin[x], Cos[x], 4, 7] or f[Sin[x], Cos[x], 4, 7] /. f -> List?
– kglr
Jul 4, 2017 at 17:11
• I meant the lists. List@@f[...] works fine! Thanks. Jul 4, 2017 at 17:15
• At least closely related: Converting a list of rules to a list of lists
– Kuba
Jul 4, 2017 at 20:45

List @@ f[1, 2, 3]


{1, 2, 3}

List @@ f[Sin[x], Cos[x], 4, 7]


{Sin[x], Cos[x], 4, 7}

or

f[Sin[x], Cos[x], 4, 7] /. f -> List


{Sin[x], Cos[x], 4, 7}

f[1, 2, 3] /. f -> List


{1, 2, 3}

you can also do something like this:

f[arg__][p_] := p @@ {arg}
Through[{f[1, 2], f[Sin[x], Cos[x], 4, 7]}[List]]

(* {{1, 2}, {Sin[x], Cos[x], 4, 7}} *)

• Thanks! This one works too. Jul 6, 2017 at 14:39
• p@arg is simpler.
– kglr
Jul 6, 2017 at 18:40