Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

The minimal working example of my problem is as follows:

l = {1, 2, 3, 4}
f[a_, b_, c_, d_] = a + b + c + d

Now, I'd like to evaluate


, but with a syntax like f[Unwrap[l]].

I don't have access to the code of 'f', and I can't simply change the way it is defined to accept a list

Basically, I am missing the functionality present in Python with the *,

def f(a,b,c,d):
    return a+b+c+d
print f(*l)
share|improve this question

marked as duplicate by R. M. Jul 8 '13 at 18:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

list = {1, 2, 3, 4}; f[a_, b_, c_, d_] = a + b + c + d; f[Sequence @@ list] ? – Dr. belisarius Jul 8 '13 at 18:36
f@@l does the trick ;) (python pah!) – Stefan Jul 8 '13 at 18:37
Related question. – Leonid Shifrin Jul 8 '13 at 18:49
Sorry, this had already been asked. – flebool Jul 8 '13 at 19:00
@rm-fr If this link should be considered canonical Q&A maybe You will put there Operate based answer. – Kuba Jul 8 '13 at 19:15
up vote 2 down vote accepted

There are two ways of doing this that are mostly equivalent. First,

f[ Sequence @@ l ]
(* 10 *)

But, the use of Sequence is to many characters, in my opinion, and there is a better way. Essentially, the notation @@ is shorthand for the function Apply which replaces the Head of an expression with another head. In the prior case, Sequence replaced the head List which was then passed into f. But, this can be used directly,

f @@ l
(* 10 *)

which replaces the head List with f.

share|improve this answer

and the third one (thanks to rm -rf)

l = {a, b, c, s};
Operate[f &, l]
f[a, b, c, s]

but in such simple case f@@l is what I use.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.