Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 4
    $\begingroup$ Module puts the symbol into the Global context (if it's not already there). Module replaces references to a global symbol with a temporary symbol (s$n, where n differs each time), which is how the localization is done. Unless you return the temporary, it gets thrown away on exit of module, but the Global symbol (whether created by use of Module, or one that was already in the Global context that module localized) will be there. $\endgroup$ Commented May 28, 2016 at 6:09
  • 2
    $\begingroup$ @ciao Why does it have to be that way? Why isn't it created in its s$n form right away? Why does it have to get through the process of becoming in form of global variable? $\endgroup$ Commented May 28, 2016 at 9:02
  • 5
    $\begingroup$ Possible duplicate of Local variables in Module leak into the Global context $\endgroup$ Commented May 28, 2016 at 15:38
  • $\begingroup$ Just to make it clear: I didn't find the linked discussion, of which this is possibly a dupe, when answering, and added a link to my answer later. Also, while this one is very closely related, the fundamental question asked here is different: it is why more than what to do with it, and so is my answer, which answers the why part primarily, from the language design p.o.v. So, to me this being a dupe is not a clear cut, which is why I am not putting a close vote now. $\endgroup$ Commented May 28, 2016 at 18:09
  • 1
    $\begingroup$ Related: "When does Mathematica create a new Symbol?" $\endgroup$ Commented May 29, 2016 at 6:07