Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Problems with Evaluate[Symbol[xxx]]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102808] Re: Problems with Evaluate[Symbol[xxx]]
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Thu, 27 Aug 2009 06:38:45 -0400 (EDT)
  • References: <h73760$b6u$1@smc.vnet.net>

Hi,

I think everything works fine, you were just using listIdentifier
instead of myListIdentifier in some places...


> In[602]:= (*Make an identifier string to hold some data*)
> myListIdentifier = "abc"
> 
> Out[602]= "abc"
> 
> In[603]:= (*here's the data*)
> myList = {{7, 8}}
> 
> Out[603]= {{7, 8}}
> 
> In[604]:= (*Now put the data into a variable with name abc*)
> Evaluate[Symbol[myListIdentifier]] = myList
> 
> During evaluation of In[604]:= Set::setraw: Cannot assign to raw \
> object 7. >>
> 
> During evaluation of In[604]:= Set::setraw: Cannot assign to raw \
> object 8. >>
> 
> Out[604]= {{7, 8}}

The error messages here come from the fact that there are already
definitions for abc when you do this, you can avoid them with:

Clear[Evaluate[myListIdentifier]]
Evaluate[Symbol[myListIdentifier]] = myList

actually when you need to control which parts of an expression need
evaluation, you should have a look at With, e.g.:

With[{symbolname = myListIdentifier},
 Clear[symbolname];
 Evaluate[symbolname] = myList
 ]

> In[605]:=
> (*Check abc holds the correct data*)
> abc
> 
> Out[605]= {{7, 8}}
> 
> In[606]:= (*Check the data can also be accessed using the \
> myListIdentifier*)
> 
> In[607]:= Evaluate[Symbol[myListIdentifier]]
> 
> Out[607]= {{7, 8}}

Here you don't need Evaluate, just Symbol[myListIdentifier] ist just a
good...

> In[608]:= (*But apparently the two items are not equal... why??*)
> abc == Evaluate[Symbol[listIdentifier]]
> 
> Out[608]= False

Change listIdentifier to myListIdentifier here, and it will work.
Again, no Evaluate neede here, on the other hand, it does no harm.

> In[609]:= (*Even worse, I can append using the reference abc, but not
> \
> using the myListIdentifier*)
> Append[abc, {3}]
> 
> Out[609]= {{7, 8}, {3}}
> 
> In[610]:= Append[Evaluate[Symbol[listIdentifier]], {3}]
> 
> Out[610]= {{3}}
> 
Again, replace listIdentifier and Evaluate is not needed.

hth,

albert


  • Prev by Date: Re: image from graphics3d - rid black line
  • Next by Date: Re: image from graphics3d - rid black line
  • Previous by thread: Problems with Evaluate[Symbol[xxx]]
  • Next by thread: Re: Problems with Evaluate[Symbol[xxx]]