Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

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.

share|improve this question

marked as duplicate by Mr.Wizard Feb 7 at 3:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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

1 Answer 1

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]
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.