# Using With[...] with a list specification as a variable [duplicate]

If you have some defined function, say f[a_, b_ c_, x], one can initialize this by using With[...] as

With[
{a = 1, b = 2, c = 3},
f[a, b c, x]
]


However I would like to be able to put my variable specification list into its own variable as:

InitializationList = {a = 1, b = 2, c = 3};


And then use it in the argument of the With[...] as

  With[
InitializationList ,
f[a, b, c, x]
]


However Mathematica 12.0 complains with saying that InitializationList is not a list of variable specifications. I have tried using Evaluate and Holdform, but I get the same error.

Any suggestions to achieve what I want or an alternative process?

• Try using Trace to see what is happening Aug 22 '19 at 10:53
• @JackLaVigne Thanks for that tip. Great diagnostic tool
– Q.P.
Aug 22 '19 at 18:21

One of the standard tricks I learn on this site is this:

init = Hold[{a = 1, b = 2, c = 3}];
init /. Hold[v_] :> With[v, f[a, b, c, x]]

(*  f[1, 2, 3, x]  *)

• Thanks, I'll give this a whirl and get back to you!
– Q.P.
Aug 22 '19 at 11:09

Another way is to use delayed assignment in the first argument of With:

With[{init := {a = 1, b = 2}},
With[init, {a, b}]]

{1, 2}


Or if you prefer to store your variable specification list as an OwnValue:

init := {a = 1, b = 2}
Unevaluated[With[init, {a, b}]] /. OwnValues[init]

{1, 2}

• Also a perfectly valid solution, very nice.
– Q.P.
Aug 22 '19 at 18:13