Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*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 1995

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

Search the Archive

Re: wierd REmove behavior

  • To: mathgroup at smc.vnet.net
  • Subject: [mg2372] Re: wierd REmove behavior
  • From: wagner at goober.cs.colorado.edu (Dave Wagner)
  • Date: Sun, 29 Oct 1995 22:48:56 -0500
  • Organization: University of Colorado, Boulder

In article <46pr4d$fve at ralph.vnet.net>,
richard j. gaylord <gaylord at ux1.cso.uiuc.edu> wrote:
>one of my students came to see me and asked what was going on in the following.
>
>In[6]:=
>Remove[c]
>
>In[7]:=
>c = 6
>Out[7]=
>6
>
>In[8]:=
>?c
>Global`c
>c = 6
>
>
>In[9]:=
>Remove[c];c = 6
>Out[9]=
>6
>
>In[10]:=
>?c
>Information::notfound: Symbol c not found.
>
>In[11]:=
>Trace[Remove[c]; c = 6]
>Out[11]=
>{Remove[Removed[c]]; Removed[c] = 6, 
> {Remove[Removed[c]], Null}, {Removed[c] = 6, 6}, 6}

Someone from WRI may post a more authoritative answer on this one,
but here's my understanding of how this works:  When you type

	Remove[c]; c=6

the parser parses this input and looks up the symbol c in the symbol
table.  Both c's refer to the same symbol table entry.  The symbol
table entry has a reference count which in this case is at least two
(in fact, it's larger because of the earlier references to c).
Removing c marks the symbol table entry as removed, but because the
reference count is non-zero, doesn't actually remove the symbol
table entry from the symbol table.  The c=6 then refers to a
symbol table entry whose name is "c" but which has been removed,
hence it prints as "Removed[c]".  This is a pathological beastie
that it's very hard to do anything useful with.

The same type of behavior is going on when you do something like this:

	x = 6;
	temp`x = 7;

Now if you evaluate x you will get 6; if you evaluate the following:

	Begin[temp`];
	x
	End[temp`];

you will get 7.  BUT if the following will give you 6 again:

	Begin[temp`]; x
	End[temp`]

Because all of the symbols are looked up in the symbol table before
the context-changing command is executed.

Anyway, this reminds me of an old joke:  A guy goes to the doctor,
he says, "Doc, it hurts when I do this."  So the doctor says,
"Then don't do that!"


		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at princon.com
		http://www.princon.com/princon


  • Prev by Date: Speed foe Mma ans Win95
  • Next by Date: Paolo's question
  • Previous by thread: wierd REmove behavior
  • Next by thread: Plotting Dynamic Flows on Simplex