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... ]
With
on SO, I posted a macro which can do this. You can just replaceWith
withModule
there, if that kind of solution fits you. $\endgroup$