Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have found that it is possible to assign variables from lists, as follows.

r = {1, 2, 3};
{a, b, c} = r;

However, if I try to do this within a With or Module statement, it does not evaluate:

With[{{x, y, z} = r}, x]
Module[{{x, y, z} = r}, x]
With[{{x, y, z} = r}, x]
Module[{{x, y, z} = r}, x]

whereas I expected it to work as:

With[{x = r[[1]], y = r[[2]], z = r[[3]]}, y]
Module[{x = r[[1]], y = r[[2]], z = r[[3]]}, y]

or even:

Module[{x, y, z}, {x, y, z} = r; y]

Why is this? Is there an accepted way to do this?

share|improve this question
related question – Kuba Aug 21 '13 at 12:54
Exactly this question was asked on SO some time ago. – Leonid Shifrin Aug 21 '13 at 13:03
Leonid's linked question is exactly what I was asking, with excellent responses. I've tried to flag this as a duplicate, but as it's not a Mathematica SE page I'm unable to. – Gyppo Aug 21 '13 at 13:19
@Gyppo This is not really a dupe here, since SO is a separate site. This leaves some room for further answers, possibly better than those in that SO question, unless that question gets migrated from SO. I would personally add / change some things in my answer there, but no time for that right now. – Leonid Shifrin Aug 21 '13 at 13:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.