MathGroup Archive 1998

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

Search the Archive

Re: Disappearing variables

  • To: mathgroup at
  • Subject: [mg13811] Re: Disappearing variables
  • From: immtwg at (Torben Winther Graversen)
  • Date: Fri, 28 Aug 1998 04:18:30 -0400
  • Organization: UNI-C
  • References: <6rr9u0$>
  • Sender: owner-wri-mathgroup at

nobody at News.Dal.Ca wrote:
: 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?

Look at f after you Remove[x]:

In[7]:= ?f

f := Removed["x"] = 123

So I think what really happens is:

In[8]:= Removed["x"] = 123

Set::write: Tag Removed in Removed[x] is Protected.

Out[8]= 123

However, the message is not printed when evaluating f. Why not?

By the way, when I use Definition to inspect f, the result depends on
wether I use StandardForm or OutputForm:

In[10]:= Definition[f] // OutputForm

Out[10]//OutputForm= f := Removed[x] = 123

In[11]:= Definition[f] // StandardForm

Out[11]//StandardForm= f := Global`x = 123

The StandardForm version seems slightly misleading.

Best regards,

  Torben Winther Graversen

  • Prev by Date: MacOS vs. Windows PC for Mathematica?
  • Next by Date: Defining differential operators question
  • Previous by thread: Re: Disappearing variables
  • Next by thread: Re: Disappearing variables