It's difficult to understand exactly what you want, but by one interpretation you don't need any special initialization at all as you are using indexed variables which would normally be the first recommendation for such questions. Perhaps the missing piece of the puzzle is a default value which can be defined with e.g. l[_] = 0
.
Module[{mu = 100, l},
l[_] = 0;
l[3] = 7;
Print[mu, l[2]];
Print[mu, l[3]];
]
1000
1007
A second interpretation is that this is a duplicate of: How to set Block local variables by code?
You could create your symbol names as strings, then use the code there, e.g.:
Join @@ MakeExpression @ Array["lambda" <> ToString@# &, 5] /.
_[vars__] :> Block[{vars}, body]
Or, if you wish to make assignments at the same time this is similar to my answer to Constructing symbol definitions for With which includes proper scoping. Adapting that answer for Module
:
SetAttributes[listModule, HoldAll];
listModule[(set : Set | SetDelayed)[L_, R_], body_] :=
set @@@ Thread[Hold @@@ {L, R}, Hold] /. _[x__] :> With[{x}, body]
Now:
vars = Join @@ MakeExpression @ Array["lambda" <> ToString@# &, 5]
vals = Array[Prime, 5]
listModule[vars = vals, lambda2 + lambda5]
HoldComplete[lambda1, lambda2, lambda3, lambda4, lambda5]
{2, 3, 5, 7, 11}
14
Of course the Array
/ MakeExpression
code could be included in your function if your input is standardized.