By referring to the Mathematica documentation, I learned to use ##2 to represent all the arguments but the first one. This is a brief way to represent a pattern matching all arguments but the first one. However, how can I do the same thing in the long Function[args. body] form?
For example, {##2}& @@ f[x1, x2, x3, x4] will give {x2, x3, x4}. Unfortunately, Function[{u1, u2}, {u2}] @@ f[x1, x2, x3, x4] only gives {x2}.
I think this occurs because the long form does not interally contain pattern matching functionality, although I find this hard to believe. So my question is whether the long form really ignores the functionality of pattern matching?
In general, are these two pure function forms identical in every aspect? That is, is the short form is just a shortcut for the long form?
Function[{u1,u2}, {u2}]is equivalent to{#2} &, yes. I don't know of any "named argument" equivalent ofSlotSequence[]. – J. M.'s missing motivation Jun 22 '13 at 03:34Functionform, you can set attributes for pure functions when defining them (using the 3rd argument). BTW, only&isFunction.#nis justSlot, denoting the nth argument (and##nisSlotSequencefor nth argument onwards), so you can actually doFunction[, {##2}]@{x1, x2, x3, x4}– rm -rf Jun 22 '13 at 04:06Function [x, {##2 & @@ x}]@f[x1, x2, x3, x4]works, although the key to give expected result is due to##2 &again. BTW, can I reproduce the result by only applying theFunction[]form? – Life Jun 22 '13 at 04:18Function[, Function[, {##2}] @@ #]@f[x1, x2, x3, x4]orFunction[, Function[, {##2}] @@ Level[#, 1]]@f[x1, x2, x3, x4]orFunction[, Rest@Level[#, 1]]@f[x1, x2, x3, x4]? – rm -rf Jun 22 '13 at 04:34Function[], you can get by with just one argument, without the need for a null first argument; thus,Function[Rest[Level[#, 1]]] @ f[x1, x2, x3, x4]orFunction[Function[{##2}] @@ Level[#, 1]] @ f[x1, x2, x3, x4]work nicely. – J. M.'s missing motivation Jun 22 '13 at 04:39&is the shorthand form ofFunction[], ponder on the result ofFullForm[{#} &], among other things. – J. M.'s missing motivation Jun 22 '13 at 04:40FullForm[{##2} &]. – m_goldberg Jun 22 '13 at 11:45