Q:

Define function of a list from a function of its elements (SetDelayed)

Consider the following:
 n = 5;
 vars = Array[x, n];
 a = 3 x[1] - 2 x[2]^2 + x[5]

How can I define a function mapping vars (i.e. a function of {x[1],x[2],...,x[n]}) to a? The following works but cannot be easily made general:
f[vars_] := a /. x[1] -> vars[[1]] /. x[2] -> vars[[2]] /. x[5] -> vars[[5]]

A:

n = 5;
var = Array[c, n]
a = 3 x[1] - 2 x[2]^2 + x[5]

ClearAll[f1]

f1[vars_] := a /.  x[i_] :> vars[[i]]

f1[var]

3 c[1] - 2 c[2]^2 + c[5]

f1[{3, 2, 1, 0, 0}]

1

f1[{3, 1, 1, 0, 1}]

8

f1[{3, 1, 100, 200, 1, 10, 1, 50}]

8

