# How can I set multiple values to local variables in a Module?

Multiple assignment is supported by Set. How can do something similar in Module expressions? If I could do it, whould there be drawbacks?

Here is what I tried so far:

g[x11_, y11_] := {xx111, yy111} = {x11, y11}

g[x11_, y11_] := Module[{{x111, y111} = {x11, y11}}, 1]

g[1, 2]


Module::lvset: Local variable specification {{x111, y111} = {1, 2}} contains {x111, y111} = {1, 2}, which is an assignment to {x111,y111}; only assignments to symbols are allowed. >>

Possible alternatives are:

ggg[x11_, y11_] :=
Module[{xx = {x11, y11}, x1, x2}, {x1 = xx[[2]], x2 = xx[[1]]}]


or

ggg[x11_, y11_] := Module[{x1111=x11, y1111=y11}, what... ]

-
"only assignments to symbols are allowed" - that's right, the scoping constructs don't allow parallel assignment in the variable list. –  J. M. is back. May 24 '13 at 3:23
In my answer to a similar question about With on SO, I posted a macro which can do this. You can just replace With with Module there, if that kind of solution fits you. –  Leonid Shifrin May 24 '13 at 11:14

## 1 Answer

As J.M. points out in his comment, the kind of multiple assignment you want is simply not supported. The closest you can get (and it is perfectly serviceable in my opinion) is

g[x11_, y11_] := Module[{x111, y111},
{x111, y111} = {x11, y11};
1]

-
en, seems declare variables and then assign separately. Anyway, this is not big problem, I just take some habits from one function elsewhere. –  HyperGroups May 24 '13 at 4:07
@Hyper, yes, that's precisely what m_goldberg does. That's how it is... –  J. M. is back. May 24 '13 at 8:24