# How to set a symbol indirectly?

I have a symbol, say x, whose calculated value is a 2nd symbol. How can I set the 2nd symbol to a given value? For example, say the value of x is one of the symbols a, b, or c. If it is a, I want to set a = 10. If it is b, I want to set b = 10. Ditto for c. But, I can use a, b, or c only if I can extract it from x. I want to do something like

x=a
%=10
Out= a=10


To complicate this just a bit, my 2nd "symbols" actually are subscripts, like Subscript[a,1], Subscript[a,1,2], Subscript[a,1,3,4]. I found a partial solution.

x=Subscript[a,3];
Subscript[x[[1]],x[[2]]=10;
Subscript[a,3]
Out(1)= 10


But how do I do this if a has n subscripts? How do I write something like

x=Subscript[a,3,4,2, ..., 5];
Subscript[a,x[[2]], ... , x[[n]]]=10

• Hold[x = 10] /. OwnValues[x] // ReleaseHold? -- BTW, I avoid subscripts for variables, and most questions about them. But then I've only been using Mathematica for a couple of decades or so. Still, OwnValues might work with them, if x is a regular symbol. Otherwise, maybe DownValues will work. Sep 14, 2016 at 2:44
• I just discovered a partial solution. Sep 14, 2016 at 2:54

Avoid the hold on the left hand side of an assignment with Evaluate.

x=a

a

Evaluate[x]=10

10

a

10

x = Subscript[b, 1]

Subscript[b, 1]

Evaluate[x] = 2

2

Subscript[b, 1]

2


But why?

• Why? Because it sounds like the OP wants reference-type variable passing... Sep 14, 2016 at 3:27
• Thank you, Mark. This seems to do the trick. I searched for "Release" in the Documentation Center and it says that Release has been superseded by Evaluate and ReleaseHold. I tried them and Evaluate seems to work the same way but not ReleaseHold. Sep 14, 2016 at 4:02
• Ah, didn't know that. I'm an old timer, so I still use Release. I'll update the answer. Sep 14, 2016 at 4:10
• Note that this will not work again. Once a is set to a number, x then evaluates to a number, as does x=a. Sep 14, 2016 at 4:13
• Sure. You can a=.. However I am still wondering why you are doing this. You may want to ask a new question about what you are actually trying to do. There is probably a better approach for that than this. Sep 14, 2016 at 4:42