# is the first argument of a pure function, #n the nth, ## are all variables and ##n all beginning with the nth variable.
Now, I would like to access the last argument. In a list, this would be mylist[[-1]]. Additionally, I would like to access all but the last argument which would be Drop[mylist,-1] for a list. Can this be achieved and if yes, how?
The reason for this is that I would like to pass all but the last argument to another function which can take different numbers of input arguments. Of course, I could change the order of the arguments, taking the last argument first, but this makes the arguments appear in a less logical order.
Example:
f1[a_:0,b_]:=a+b; f2[a_:0,b_,c_]:=f1[a,b]*c If I wanted to write f2 as a pure function, how would I do this?
f = {##}[[-1]] &? $\endgroup$f2 = With[{args = {##}}, f1 @@ Most[args] Last[args]] &$\endgroup$f2[a_:0, b__,c_]:=f1[a,b]*c, notice double_next tob, it stands for one or more arguments. $\endgroup$