If I correctly interpreted the question, you want to define a list of variables and related values externally to a With construct, and then inside the With you want to automatically assign those values to variables, but without to influence the values of such variables outside the With itself. In other words, exactly what With does, but using parallel assignments in automatic.
Because parallel assignment is not allowed inside scoping constructs like With (and Module for instance) the effort is to find a way to overcome such limit.
Some solutions offered in previous answers are not fully working, despite the apparent correct behavior. See for instance the following
Clear[a,b,c,d];
params = {a, b, c, d};
vals = {1, 2, 3, 4};
With[{list = {#1 -> #2} & @@@ Thread[{params, vals}] //
Flatten},(*fancy operation*){a, b, c, d} /. list]
{1, 2, 3, 4}
it seems it works, but looking at other operations
params = {a, b, c, d};
vals = {1, 2, 3, 4};
With[{list = {#1 -> #2} & @@@ Thread[{params, vals}] // Flatten},
(*fancy operation*)
e = a + b + c + d;
Print[{a, b, c, d} /. list];
Print[e]]
{1,2,3,4}
a+b+c+d
event the other solution seems to have a side effect that at the end vanishes the use of With.
Clear[a,b,c,d];
params = ToExpression@CharacterRange["a", "z"];
vals = Range[26];
With[{tmp$ = Quiet@Set[#1, #2] & @@@ Thread[params -> vals]}, #*2 & /@
ToExpression@CharacterRange["a", "z"]] // Total
702
the result is correct but the variables inside params are now defined outside the With statement, and this makes unuseless the With itself
params
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}
vals
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}
so starting from the solution proposed by Michael E2, then I found an easier solution.
Clear[a,b,c,d];
myWith[vars_List, values_List, expr_] := Module[vars, MapThread[Set, {vars, values}]; expr]
myWith[{a, b, c, d}, {1, 3, 5, 7}, Range[4].{a, b, c, d}]
(* 50 *)
myWith[{a, b, c, d}, {10, 3, 5, 7}, Range[4].{a, b, c, d}]
(* 59 *)
{a, b, c, d}
{a, b, c, d}
myWith[ToExpression@CharacterRange["a", "z"],
Range[26], #*2 & /@ ToExpression@CharacterRange["a", "z"]] // Total
702
and still the variables are not defined outside the With
ToExpression@CharacterRange["a", "z"]
{a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z}