MathGroup Archive 1997

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

Search the Archive

Re: Symbols, names, objects: kludge

  • To: mathgroup at smc.vnet.net
  • Subject: [mg6533] Re: [mg6517] Symbols, names, objects: kludge
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Mon, 31 Mar 1997 23:01:33 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

murray at math.umass.edu (Murray Eisenberg)
[mg6517] Symbols, names, objects: kludge

>>>>>>>>>>>.
In an earlier posting, I asked how to define a function
store[varname_String, dataname_String] that causes a variable to be
created whose name is given by the string used as first argument and
which assigns as the value of that new variable the value of the
object whose name is given by the string used as the second argument.
For example,

   x = 99;
   store["myx", "x"]

should mean that an input

   myx

now produces

   99

as output.

I found one method that works -- sort of, and sometimes -- but which I
don't fully understand:

   store[varname_String, dataname_String] :=
      ToExpression[StringJoin[Sequence@@{varname,"=",dataname}]]      

Unfortunately, I need to use such a function store inside a Module,
like this:

   wrapper[shortname_String] := Module[{temp},
      temp = ...... (* value created here *) ;
      store["new"<>shortname, "temp"];
      ....
      ]

and now, because temp is a local variable in the Module, the whole
thing breaks down (assigning the SYMBOL temp as the value of the
new... variable).
<<<<<<<<<<<

Murray:
With your definition
  store[varname_String, dataname_String] :=
      ToExpression[StringJoin[Sequence@@{varname,"=",dataname}]]

How about this sort of thing --

wrapper[shortname_String] := Module[{temp},
      temp = 3 ;
      store["new"<>shortname, ToString[temp]]
      ]

wrapper["aa"]
	3
newaa
	3
??

Allan Hayes
hay at haystack.demon.co.uk
http://www.haystack.demon.co.uk


  • Prev by Date: Re: NDSolve problem
  • Next by Date: Fwd: Symbols, names, objects
  • Previous by thread: Re: Symbols, names, objects
  • Next by thread: Re: Symbols, names, objects: kludge