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

MathGroup Archive 2006

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

Search the Archive

Re: Clearing a symbol known only through a definition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66710] Re: Clearing a symbol known only through a definition
  • From: Peter Pein <petsie at dordos.net>
  • Date: Sat, 27 May 2006 03:53:07 -0400 (EDT)
  • References: <e56e69$1v3$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Andrew Moylan schrieb:
> Suppose I have a symbol "a" that is defined to be equal to another 
> symbol. (E.g. It might be that a := b.) How can I clear the value of the 
> symbol 'pointed to' by "a", without knowing explicity what symbol that is?
> 
> Clear[a] won't do, of course.
> Clear[Evaluate[a]] won't do, because that will evaluate to 
> Clear[Evaluate[b]], which will in turn (in general) evalulate to 
> Clear["whatever b evalulates to"].
> 
> ----
> Alternatively, here is the particular problem I want to solve:
> 
> For any expression e, either e is a symbol, or Head[e] is, or 
> Head[Head[e]] is, etc. Call this the "topmost symbol" in the expression. 
> Thus, the topmost symbol in f[x][y][z] is f.
> 
> I want to write a function that takes an expression and calls Clear[] on 
> its topmost symbol. Can anyone think of a simple way to write such a 
> function?
> 


Hi Andrew,

OwnValue[] is what you're looking for:

b=5;a:=b; a
--> 5

b=3;a
--> 3

OwnValues[a]
--> {HoldPattern[a] :> b}

ReleaseHold[Clear/@(Hold[a]/.OwnValues[a])]; a
--> b


hth,
   Peter


  • Prev by Date: Re: What does " 1.' " mean ?
  • Next by Date: Re: Output Table Format Change
  • Previous by thread: Re: Clearing a symbol known only through a definition
  • Next by thread: RE: Clearing a symbol known only through a definition