2

I have a list of variables (say a, b, c, d, e) that I want to assign in a single command.

{a,b,c,d,e} = {1,2,3,4,5}

would work, but it is cumbersome to type {a,b,c,d,e} each time. Is there a way I can create a table that holds references to these variables, and whenever I assign to this table, the actual variables a,b,c,d,e will get assigned?

Sorry for the question - I am new to Mathematica and do not even know the basic terms. If you guessed I have a C++ background, you are right.

Kuba
  • 136,707
  • 13
  • 279
  • 740

1 Answers1

4

Most user friendly approach, with function:

mySet[l_] := {a, b, c, d, e} = l

I'm not sure what is the general goal, but here's one way with UpValues:

table /: Set[table, l_] := ({a, b, c, d, e} = l);

table = Range[6, 10]; 
{a, b, c, d, e}
{6, 7, 8, 9, 10}
table = Range[1, 5];
{a, b, c, d, e}
{1, 2, 3, 4, 5}

Different approach:

list := {a, b, c, d, e};  
Unevaluated[list = {1, 2, 3, 4, 5}] /. OwnValues[list]
Kuba
  • 136,707
  • 13
  • 279
  • 740