I know that I can define a function of a List and get the nth argument like:


What if the argument of f is not a list? I.e. how to define an equivalent function for


This is probably extremely basic, but I couldn't figure it out from the Slot documentation.


With f[x__Integer] := ... you can use


to get the ith argument.


Szabolcs's answer (wrapping the sequence x with List and using Part) is the way.

An alternative is to use Indexed


f2[x__Integer] := Indexed[{x}, 1] + Indexed[{x}, 2]
f2[1, 2, 3, 4, 5]


You can also use Slot (#):

ClearAll[f3, f4]

f3[x__Integer] := Slot[1] + Slot[2] &[x]
f3[1, 2, 3, 4, 5]


f4[x__Integer] := #1 + #2 &[x]
f4[1, 2, 3, 4, 5]


but you can use a pure function directly to define your function:

f5 = #1 + #2 &
  • $\begingroup$ Thanks. Is the pure function method likely to be faster than the Indexed/List methods? $\endgroup$ – user366202 Oct 14 at 14:24
  • $\begingroup$ @user366202, I am not sure. $\endgroup$ – kglr Oct 14 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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