Previously, I've defined a function with a variable number of arguments with the following method.
x = {x1, x2, x3};
f1 = Function[
Evaluate[x],
x + 1 //
Evaluate
];
f1 @@ x
Output: {1 + x1, 1 + x2, 1 + x3}
Also, I've defined a function that returned a function as follows.
g[x_] := Function[
{z},
x + z //
Evaluate
];
f2 = g @@ {z};
f2 @@ {x1}
Output: x1 + z
But when I attempt to put these ideas together, I have an issue. The hang-up seems to be in passing the argument of the first function to the argument of the second. Note that in our second example, above, we weren't passing x
as an argument to the inner function. However, this is exactly what we want to do:
h[x_] := Function[
Evaluate[x],
x + 1 //
Evaluate
];
f3 = h @@ x;
f3 @@ x
Output: h[x1, x2, x3][x1, x2, x3]
The desired output is {1 + x1, 1 + x2, 1 + x3}
. My motivation for writing such a function is to bury it in a package.