In the documentation ref/$ModuleNumber, I read:

Every Wolfram System session starts with $ModuleNumber set to 1.

Yet, when I quit Mathematica 10.1 (OS X 10.10.4), restart it, open a new notebook and enter:

In[1]:= $ModuleNumber

Out[1]= 1370

Something wrong here?

Secondly, in the documentation ref/$ModuleNumber, I read:

$ModuleNumber is incremented every time Module or Unique is called.

Yet, each time I enter $ModuleNumber, it is updated.

In[2]:= $ModuleNumber

Out[2]= 1869

In[3]:= $ModuleNumber

Out[3]= 1870

In[4]:= $ModuleNumber

Out[4]= 1871

And it doesn't start with 1371. Something strange going on?

P.S. I also got the same results when I shut my machine down, then restarted the machine, then restarted Mathematica.

Feedback from Wolfram Technical Support:

Thanks for contacting Wolfram Technical Support and for taking the time to send in the feedback. I agree with you that the documentation is misleading, but the observed behaviour is as designed.

Everytime Mathematica is launched, the \$ModuleNumber does reset to 1. However during the startup process, a lot of system-level functions will get loaded and many of them will localize their variables and therefore change the \$ModuleNumber counter. So when you start to evaluate your own statement, the \$ModuleNumber will be set to a different number.

Similarly, when you evaluate a command in the front-end, the communication between the front-end and the kernel also uses functions that will change the counter. This is why even if you simply do an evaluation, the \$ModuleNumber will increase. This is not specific to the evaluation of \$ModuleNumber, but any evaluations happen in the frontend.

We are sorry for the confusion caused by the documentation. Please let me know if you have further concerns.

  • 6
    $\begingroup$ Might have to do with Module being invoked at start-up time to deal with that part of Mathematica that is written in the Wolfram Language. As for the rest, note that there is no documentation to the effect that nothing else changes $ModuleNumber $\endgroup$ – Daniel Lichtblau Jul 6 '15 at 23:11

The first result is no mystery as Module is used plentifully in internal functions and packages.

The second result is a little surprising as there is no apparent use of Module for input in a default configuration, yet $ModuleNumber increases by one for each input cell. Note that it does not increase for each use of $ModuleNumber or for each line of input, e.g. all in one cell:




It is plausible that Kernel evaluation still uses Module or Unique however.

  • $\begingroup$ I went ahead and reported this using Help->Give Feedback (Mathematica menu). $\endgroup$ – David Jul 7 '15 at 1:33
  • $\begingroup$ I got this feedback from Wolfram Technical Support. I've placed it in my original posted question. $\endgroup$ – David Jul 8 '15 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.