1

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!

Javier Garcia
  • 297
  • 2
  • 6

2 Answers2

2
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}

kglr
  • 394,356
  • 18
  • 477
  • 896
0

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}} *)
Ali Hashmi
  • 8,950
  • 4
  • 22
  • 42