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!
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!
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}} *)
[Sin[x],Cos[x],4,7]is not a valid Mathematica expression. Maybe you can trySequence @@ f[Sin[x], Cos[x], 4, 7]orf[Sin[x], Cos[x], 4, 7] /. f -> SequenceorList @@ f[Sin[x], Cos[x], 4, 7]orf[Sin[x], Cos[x], 4, 7] /. f -> List? – kglr Jul 04 '17 at 17:11List@@f[...]works fine! Thanks. – Javier Garcia Jul 04 '17 at 17:15