MathGroup Archive 1999

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

Search the Archive

Re: Question on symbols in modules

  • To: mathgroup at
  • Subject: [mg17959] Re: Question on symbols in modules
  • From: "Allan Hayes" <hay at>
  • Date: Mon, 7 Jun 1999 02:51:18 -0400
  • References: <7jaj3f$>
  • Sender: owner-wri-mathgroup at

I insert some explanations below.

Allan Hayes
Mathematica Training and Consulting
Leicester UK
hay at
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

David Keith <dkeith at> wrote in message
news:7jaj3f$k13 at
> Perhaps I am confused about symbols in modules, and also about evaluation.
> execute the lines below in V4.0 on NT4.0/SP3:
> In[1]:= Names["Global`*"]
> Out[1]= {}
> In[2]:= test[] := Module[{tmp}, Return[tmp]]
> In[3]:= Names["Global`*"]
> Out[3]= {"test", "tmp"}

Before any evaluation the expression
        test[] := Module[{tmp}, Return[tmp]]
has been parsed and the symbols  test and tmp have been created in the
context "Global`"
The right side has not been evaluated, so no local symbol has been created.

> In[4]:= test[]
> Out[4]= tmp$5

Module[{tmp}, Return[tmp]] has been evaluated; the local symbol tmp$5 has
been created (in the context "Global`").

Incidentally, Return is not needed.

> What confuses me is this: line In[2] defines a module with local symbol
> "tmp".

 -- rather: a Module that when evaluated will create a local variable from
tmp has been stores as the right side of a rule.

> But following this line, a symbol "tmp" has been created in Global
> context. I thought this would not happen, that the only symbol ever
> would be a temporary symbol, some "tmp$N". Further, I thought that the
> hand side of In[2] would not actually be evaluated until called.
> In[4] / Out[4] does display the behaviour I expected, a temporary symbol
> used within the scope of the module, but why is "tmp" ever created?

Symbols (tmp) have to be created *before any evaluation* as part of the
process of trying to interpret the input.
Local versions of these symbols are created only when Module is evaluated.

  • Prev by Date: Question on NonlinearFit
  • Next by Date: NDSolve - large ODE systems
  • Previous by thread: Re: Question on symbols in modules
  • Next by thread: reynolds and dimensionless