Re: Disappearing variables

*To*: mathgroup at smc.vnet.net*Subject*: [mg13785] Re: Disappearing variables*From*: "Allan Hayes" <hay at haystack.demon.cc.uk>*Date*: Fri, 28 Aug 1998 04:18:13 -0400*References*: <6rr9u0$15b@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

nobody at News.Dal.Ca wrote in message <6rr9u0$15b at smc.vnet.net>... >I want to to define a variable inside a function, as follows: f:=x=123; >Whenever I run f, x should be given the value of 123, and if x doesn't >exist, it should be created. However: > >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 > >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? > >Vilis Nams > > Vilis, Let's look at the assignments that are stored: f:=x=123; ?f "Global`f" f := x = 123 Remove[x] ?f "Global`f" f := Removed["x"] = 123 ?x Information::notfound: Symbol x not found." So, f still evaluates with output 123 but it does not restore the assignment x=123 nor recreate x; and i is it allowed to assign Remove["x]" = 123. Removed["x"] Removed["x"] ------------------------------------------------------------- Allan Hayes Training and Consulting Leicester UK http://www.haystack.demon.co.uk hay at haystack.demon.co.uk voice: +44 (0)116 271 4198 fax: +44(0)116 271 8642