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.

I am trying to extract variable names from a list of transformation rules mapping = {var1 -> 'val1', var2 -> 'val2' }. Variables var1 and var2 are already defined in my notebook:

var1 = 'init-val1'; var2 = 'init-val2';

When I try to evaluate Extract[mapping, {1,1}, HoldForm], I get 'init-val1', instead of var1.

What am I doing wrong? Why is var1 getting evaluated despite the explicit HoldForm wrapper? How can I fix the problem?

share|improve this question
Check your mapping... the evaluation has already happened when you assigned it to mapping, so the HoldForm is useless. If you explained the intent behind what you're trying to do, then perhaps we can provide a solution that doesn't involve playing catch up with the evaluator. –  rm -rf Feb 16 '14 at 21:30
@rm-rf, when I evaluate Definition[mapping] I still get {var1 -> 'val1', var2 -> 'val2' }. So in the definition I don't get the substitution of var1 for 'init-val1'. –  verse Feb 16 '14 at 21:32
var1 = "init-val1"; mapping = {var1 -> "val1", var2 -> "val2"}; Definition[mapping] gives mapping = {"init-val1" -> "val1", var2 -> "val2"}as expected –  belisarius Feb 16 '14 at 21:38
@belisarius If you do it the other way round, Definition will give you what the OP said. This is different, because in your case, clearing var1 has no effect on mapping but it does in this one. –  rm -rf Feb 16 '14 at 22:01
@rm-rf So what does "Variables var1 and var2 are already defined in my notebook:" mean? –  belisarius Feb 16 '14 at 22:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.