Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
list = {1, 2, 3, 4}; f[a_, b_, c_, d_] = a + b + c + d; f[Sequence @@ list] ? –  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
add comment

marked as duplicate by rm -rf 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.

2 Answers

up vote 1 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
add comment

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
add comment

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