given a list of variables
variables = {a, b, c};
I want to automatically define a function
f[{a_,b_,c_},x_] := g[a,b,c,x]
(I do need a delayed assignment here, since g is a compiled function).
As a first attempt I define
f[Evaluate[Pattern[#,Blank[]]&/@variables], x_] := Evaluate[Append[variables, x]]
which works out as
?f
f[{a_,b_,c_},x_]:={a,b,c,x}
This is good so far.
As a next step I want to pass the parameter list to the function g:
f[Evaluate[Pattern[#,Blank[]]&/@variables], x_] := g @@ Evaluate[Append[variables, x]]
This does not work, as the argument list for g is now left unevaluated:
?f
f[{a_,b_,c_},x_]:=g@@Evaluate[Append[variables,x]]
What do I need to change in my definition of f in order to get
?f
f[{a_,b_,c_},x_]:=g[a,b,c,x]
Thanks for any help! Roman
f[p : Pattern @@@ Thread[{variables, _}], x_] := g[## & @@ p, x]
? $\endgroup$