Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Interaction of Remove and Global variables in a Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120042] Interaction of Remove and Global variables in a Module
  • From: blamm64 <blamm64 at charter.net>
  • Date: Thu, 7 Jul 2011 07:28:13 -0400 (EDT)

This is what I get for querying SetDelayed

In[1]:= ?SetDelayed
lhs:=rhs assigns rhs to be the delayed value of lhs. rhs is maintained
in an unevaluated form. When lhs appears, it is replaced by rhs,
evaluated afresh each time.  >>

Note particularly the above reads AFRESH EACH time.  It appears then
the following is inconsistent behavior based on the above description:

In[2]:= f[b_]:=Module[{t},a[t_]=b*t^2;]
In[3]:= a[t]
Out[3]= a[t]
In[4]:= f[3]
In[5]:= a[t]//InputForm
Out[5]//InputForm=
3*t^2
In[6]:= f[5]
In[7]:= a[t]//InputForm
Out[7]//InputForm=
5*t^2
In[8]:= Remove[a]
In[9]:= f[4]
In[10]:= a[t]//InputForm
Out[10]//InputForm=
a[t]

Apparently AFRESH is not an accurate description of how SetDelayed
operates in this case, or I am missing something about this particular
interaction of Module, Remove, and global variables inside Modules.

However, if I go back, after executing the last line above (<a> has
been Removed), and place the cursor in the input line where <f> is
defined and hit Enter, which I thought would be identical to just
evaluating <f> AFRESH again, and then execute the <f[4]> line again,
then the global <a> definition is re-constituted.

The documentation for Remove reads the name is no longer recognized by
Mathematica.  My understanding is that if the same name is defined
AFRESH, it will once again be recognized.

So if anyone would let me know what I am missing, regarding why the
definition of <a> is not created AFRESH each time <f> is evaluated, I
would appreciate it.

Please don't construe the definition of <f> as my way of
'parameterizing' a function definition, I just use that definition to
convey the apparent inconsistency.

-Brian L.


  • Prev by Date: Re: Numerical accuracy/precision - this is a bug or a feature?
  • Next by Date: Re: How can I get better solution for this...?
  • Previous by thread: Re: Bug 1+4/10
  • Next by thread: Re: Interaction of Remove and Global variables in a Module