Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Disappearing variables

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

On 28 Aug 1998, Allan Hayes wrote:

|nobody at News.Dal.Ca wrote in message <6rr9u0$15b at>... |>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;
|>Out[3]:=123        ** x exists
|>Out[5]:=123  ** f seems to work
|>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
|Let's look at the assignments that are stored: |
|f := x = 123
|f := Removed["x"] = 123
|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.

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[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