MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Fwd: strings & expressions in Module

  • To: mathgroup at
  • Subject: [mg6253] Fwd: [mg6244] strings & expressions in Module
  • From: BobHanlon at
  • Date: Mon, 3 Mar 1997 01:29:06 -0500
  • Sender: owner-wri-mathgroup at

Either of the following:

Module[{y = 99}, Evaluate[ToExpression["y"]]]


Module[{y}, y = 99; Evaluate[ToExpression[
    "y$" <> ToString[$ModuleNumber-1]]]]

Forwarded message:
From:	murray at (Murray Eisenberg)
To: mathgroup at
To:	mathgroup at

Naively, I expect the following, when evaluated, to return result 99:

   y = 99;
   Evaluate at ToExpression["y"]

But it doesn't; instead, it returns:


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
  Mathematics & Statistics Dept.            Voice:  413-545-2859 (W)
  University of Massachusetts                       413-549-1020 (H)
  Amherst, MA 01003                           Fax:  413-545-1801

  • Prev by Date: Solaris, MMA 3.0, and Postscript
  • Next by Date: plotting a 3D cloud of points
  • Previous by thread: Solaris, MMA 3.0, and Postscript
  • Next by thread: Re: strings & expressions in Module