MathGroup Archive 2008

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

Search the Archive

Re: ClearAll error message

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92357] Re: ClearAll error message
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Mon, 29 Sep 2008 07:05:49 -0400 (EDT)
  • Organization: University of Bergen
  • References: <gbnpep$pr3$1@smc.vnet.net>

carlos at colorado.edu wrote:
> Just out of curiosity.  The following ClearAll works as expected.
> 
>   name=Symbol["A"]; ClearAll[name];

This series of commands will not clear the definitions associated with 
symbol A.  It will only clear the symbol name.

> 
> But this elicits an error message:
> 
>   ClearAll[Symbol["A"]];
> 
> Why?  A non-standard argument evaluation?

After reading the documentation ("Symbol["name"] refers to a symbol with 
the specified name."), one might think that Symbol["A"] is equivalent to 
A.  But it turns out that this is not exactly true.

Symbol["A"] becomes A only after it is evaluated.  Since ClearAll has 
the attribute HoldAll, it will not evaluate Symbol["A"] before checking 
that it is atomic, and it will see a compound expression.

The good news is that ClearAll works with symbol *names* (strings) 
directly, so you can just use ClearAll["A"].  Another solution for 
similar situations is to use ToExpression["A", InputForm, ClearAll].

> 
> [The message came deep from the bowels of a complicated code
> to find tensor invariants. A module received a string from which to
> build related symbol names with that string as root]

Before resorting to building symbol names as strings (e.g. name1, name2, 
etc.), it is a good idea to consider using expressions (name[1], 
name[2], etc.).



  • Prev by Date: Glitch in NumberFieldFundamentalUnits
  • Next by Date: Re: Help
  • Previous by thread: Re: ClearAll error message
  • Next by thread: Re: ClearAll error message