MathGroup Archive 1998

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

Search the Archive

Re: Disappearing variables

  • To: mathgroup at
  • Subject: [mg13788] Re: [mg13759] Disappearing variables
  • From: David Withoff <withoff>
  • Date: Fri, 28 Aug 1998 04:18:15 -0400
  • Sender: owner-wri-mathgroup at

> In[1]:= f:=x=123;
> In[2]:=f
> Out[2]:=123
> In[3]:=x
> Out[3]:=123        ** x exists
> In[4]:=Remove[x];
> In[5]:=f
> Out[5]:=123  ** f seems to work
> In[6]:=x
> Out[6]:=x     ** x doesn't exist anymore, even though f worked

This behavior can be understood by looking at the rule for f:

    In[7]:= ?f

    f := Removed["x"] = 123

With this rule, evaluation of f will give an assignment to the "removed"
symbol x.  The x entered in In[6] is a different symbol, since symbols
that have been removed are no longer recognized in input.

> It seems like x is created when I initially define f, whereas since f is
> SetDelayed,  x should be created when I run f.  Does anyone know why x
> is not created when I run f?

x is created when the input is initially read, since it is needed to
represent the input, regardless of the meaning of the input (such as
whether it involves immediate or delayed assignments).  If you want x
to be recreated each time f is evaluated, it is necessary to do that
explicitly, as in

In[8]:= f := Evaluate[Symbol["x"]] = 456 In[9]:= f
Out[9]= 456
In[10]:= Remove[x]
In[11]:= f
Out[11]= 456
In[12]:= x
Out[12]= 456

Dave Withoff
Wolfram Research

  • Prev by Date: An operator called-- LocalRule
  • Next by Date: A Most Annoying Problem
  • Previous by thread: Disappearing variables
  • Next by thread: Re: Disappearing variables