MathGroup Archive 1998

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

Search the Archive

Re: Disappearing variables

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13826] Re: Disappearing variables
  • From: Julian Stoev <stoev at usa.net>
  • Date: Sat, 29 Aug 1998 04:41:06 -0400
  • Organization: Seoul National University, Republic of Korea
  • References: <6rr9u0$15b@smc.vnet.net> <6s5khr$c62@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 28 Aug 1998, Allan Hayes wrote:

|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"]

Let me add something. If you try:
In[1]:= SetDelayed[f,Set[x,123]]
In[2]:= x
Out[2]= x
In[3]:= f
Out[3]= 123
In[4]:= x
Out[4]= 123

, you will find, that x has a value only after you check for f and this
is logical, because when you check for f, it executes Set[x,123].

The only problems I see are, that Removed[] is not mentioned in the
Mathematica book and in the help. The info I found about it is In[5]:=
?Removed
"Removed[string] is printed to indicate a symbol that has been removed."

Also it is not very clear how x got defined somehow if SetDelayed has
attributes HoldAll. Even when I tried

In[1]:= SetDelayed[f,HoldComplete[Set[x,123]]]

I got

In[2]:= x
Out[2]= x

--Julian Stoev



  • Prev by Date: Re: FresnelS & FresnelC
  • Next by Date: Re: Function as an argument to a function
  • Previous by thread: Re: Disappearing variables
  • Next by thread: Re: Disappearing variables