MathGroup Archive 2000

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

Search the Archive

string-variable-Set-snarl

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22491] string-variable-Set-snarl
  • From: James Fuite and Tania Nordli <jfuite at UAlberta.ca>
  • Date: Sun, 5 Mar 2000 00:24:27 -0500 (EST)
  • Organization: University of Alberta, Edmonton, Canada
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Advanced Mathematica Users,

 The following is a short and perhaps trivial problem that has caused me
some frustration.  I cannot write a program that allows me to change the
value of any given variable if given the name of the variable as a
string.  What follows is an equivalent situation.  Let

In[3]=      {cow = Random[], emu = Random[], ant = Random[]}
Out[3]=    {0.2, 0.3, 0.4}

       . . . . some selection process . . . .

In[25]=      animalname
Out[25]=    cow

In[25]=     Head[animalname]
Out[25]=   String

Given a string, here "cow", corresponding to a variable, here cow, I
cannot clear or set a value for the variable itself.  Of course I cannot
use Clear[cow] or cow = 2 because I do not know which variable will be
chosen, as represented by the variable animalname.  My lame attempts
such as Clear[animalname] or ToExpression[animalname] = 2 only fail to
affect cow - it seems that I am caught trying to work on the wrong side
of the equals sign (Set)!  My goal would be a line such as:

In[28]=      ToExpression[animalname]
Out[28]=    2

which I think would imply that cow = 2 and has thus been affected.  Who
can guide me from line 25 to line 28?  What are the general
considerations?

   Sincerely,
   James J. Fuite.



  • Prev by Date: Help
  • Next by Date: Re: Digitizing points in a graphic
  • Previous by thread: string-variable-Set-snarl
  • Next by thread: Re: string-variable-Set-snarl