2
$\begingroup$

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.

$\endgroup$
5
  • 1
    $\begingroup$ Is something like that ok: list := {a, b, c, d, e}; Unevaluated[list = {1, 2, 3, 4, 5}] /. OwnValues[list]? $\endgroup$ Commented Jan 30, 2015 at 9:40
  • $\begingroup$ related: 40094 $\endgroup$ Commented Jan 30, 2015 at 9:46
  • $\begingroup$ less related: 70250 $\endgroup$ Commented Jan 30, 2015 at 9:54
  • $\begingroup$ Proposed duplicate: (10322). Also related: (6511) (and see links below that one) $\endgroup$ Commented Jan 30, 2015 at 10:16
  • $\begingroup$ The functional programmer might wonder, why would you want to do that ? ;) $\endgroup$ Commented Jan 30, 2015 at 10:24

1 Answer 1

4
$\begingroup$

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] 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.