Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1997
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

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

Search the Archive

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




  • 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