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?
mapping... the evaluation has already happened when you assigned it tomapping, so theHoldFormis 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:30Definition[mapping]I still get{var1 -> 'val1', var2 -> 'val2' }. So in the definition I don't get the substitution ofvar1for'init-val1'. – verse Feb 16 '14 at 21:32var1 = "init-val1"; mapping = {var1 -> "val1", var2 -> "val2"}; Definition[mapping]givesmapping = {"init-val1" -> "val1", var2 -> "val2"}as expected – Dr. belisarius Feb 16 '14 at 21:38Definitionwill give you what the OP said. This is different, because in your case, clearingvar1has no effect onmappingbut it does in this one. – rm -rf Feb 16 '14 at 22:01mappingis defined before or after. Your interpretation is certainly valid given what OP wrote, but if that were the case, then they won't get the output above. That's why I asked OP to explain what they want to do. – rm -rf Feb 16 '14 at 22:13var1andvar2were defined,mappingsevaluation used their values instead of name. I had to redefinemappingsusingHoldForm. – verse Feb 16 '14 at 23:15