3

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

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

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]
2
2

or even:

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

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

Kuba
  • 136,707
  • 13
  • 279
  • 740
Samizdis
  • 163
  • 6

0 Answers0