Re: Disappearing variables

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

> 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 Global`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