Fwd: strings & expressions in Module
- To: mathgroup at smc.vnet.net
- Subject: [mg6253] Fwd: [mg6244] strings & expressions in Module
- From: BobHanlon at aol.com
- Date: Mon, 3 Mar 1997 01:29:06 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Either of the following: Module[{y = 99}, Evaluate[ToExpression["y"]]] 99 Module[{y}, y = 99; Evaluate[ToExpression[ "y$" <> ToString[$ModuleNumber-1]]]] 99 --------------------- Forwarded message: From: murray at math.umass.edu (Murray Eisenberg) To: mathgroup at smc.vnet.net To: mathgroup at smc.vnet.net Naively, I expect the following, when evaluated, to return result 99: Module[{y}, y = 99; Evaluate at ToExpression["y"] ] But it doesn't; instead, it returns: y I suspect the problem is that, inside the Module, y is not really y but rather y$1 or some symbol of the kind. How can I modify the string "y" so that, in fact, the result returned is the value 99 stored into y? (Yes, this likes a strange thing to do: assign a value to a symbol inside a Module and then try to refer to the symbol indirectly by a string giving its name. There's a good reason I want to do this!) -- Murray Eisenberg Internet: murray at math.umass.edu Mathematics & Statistics Dept. Voice: 413-545-2859 (W) University of Massachusetts 413-549-1020 (H) Amherst, MA 01003 Fax: 413-545-1801