I have a list of variables variables={a,b} and a list with values values={1,2}. I'd like to define a function using the variables in variables like so:
f=Function[variables,2a+b];
Then, I'd like to call it in a way like
result=f@@values
or
result=f@@variables/.(Rule@@@Transpose@{variables,values})
or something similar.
Is there a way to create a function where the names of the variables are in a given list?
_[vars__]? (I suppose_[]matches theHold[], and__for the list of variables, because we want the whole list, not just one element.) – Ragnar Jan 14 '14 at 21:44vars__is a pattern that represents an arbitrary sequence of expression namedvars(seeBlankSequencein the docs) -- it matchesa, binHold[a, b]. This sequence is then inserted in the place ofvarson the right-hand-side of:>(SetDelayed), formingFunction[{a, b}, . . .]. See this for another example. – Mr.Wizard Jan 14 '14 at 21:49