Pattern matching here is a functional programming term, but it might be called differently in Mathematica, I'm not sure. It is possible to match the elements of the list in a regular function definition:

f[{x_, y_}] := {x + 1, y + 2}
f[{a, b}]

which results in {1 + a, 2 + b}.

I'd like to do the same matching in a pure function. The following code does not work the same way as the regular function definition. It is to demonstrate my intention:

Function[{{x, y}}, {x + 1, y + 2}][{a, b}]

Is it possible to have use this matching mechanism in a pure function definition?

  • 1
    $\begingroup$ Function[r, r /. {x_, y_} -> {x + 1, y + 2}][{a, b}]? $\endgroup$ – Dr. belisarius Oct 22 '13 at 15:50