Possible Duplicate:
How do I clear all user defined symbols?

The normal way I reset the Mathematica kernel to its initial state is through the notebook interface: Evaluation menu, Quit Kernel item, Local submenu, then the Quit confirmer button in the resulting dialog box. I do this often enough that my fingers know the drumbeat: Alt-V Q L Q.

But I really need a way to set things back to normal from code. I suppose I could go

ClearAll /@ Names["Global`*"]

or even

Remove /@ Names["Global`*"]

which does much of what I want, but seems really ham-handed to me, and doesn't really guarantee a complete system reset -- at least I don't think.

There is also the ancient CleanSlate utility, which I can call from inside a notebook or package, but I have heard rumors that it's deprecated and unsupported:

Mathematica graphics

My attempts to search the documentation and Mathematica graphics for something resembling Reset or Restart or Clean yielded nothing useful.


EDIT: In case you're wondering, I want this for unit-testing big Packages, where I want to Reset in the unit-testing scripts so that I can have deterministic values for results of certain Unique[] evaluations.

EDIT: I found Quit[] and Exit[]. That may be as close as we can get. I do not see any difference in them

Mathematica graphics

  • 2
    $\begingroup$ I wouldn't rely on specific numbers from Unique[]. They could very easily change from version to version. $\endgroup$ – Brett Champion Jun 21 '12 at 20:19
  • $\begingroup$ I'm willing to update my unit tests at version-change boundaries . . . in any event, there might be other good reasons to do a reset. $\endgroup$ – Reb.Cabin Jun 21 '12 at 20:32
  • 1
    $\begingroup$ You (or anyone else) might find this thread about removing a loaded package from memory useful. $\endgroup$ – István Zachar Jun 21 '12 at 20:49
  • $\begingroup$ apologies -- didn't realize it was a duplicate till we got into the answers. $\endgroup$ – Reb.Cabin Jun 22 '12 at 17:43
  • $\begingroup$ Maybe I'm too late for the discussion, but the documentation of Exit says, "Exit is a synonym for Quit. " $\endgroup$ – luyuwuli Sep 1 '15 at 12:33

Does running Quit[] do what you want?

| improve this answer | |
  • 2
    $\begingroup$ You don't even need the []. $\endgroup$ – Brett Champion Jun 21 '12 at 21:17
  • 2
    $\begingroup$ @BrettChampion I've been wasting my life away! Thanks. $\endgroup$ – ArgentoSapiens Jun 21 '12 at 21:58
  • 1
    $\begingroup$ @Brett doesn't that go against the Mathematica paradigm? Aren't nearly all other actions made with the form Action[]? This seems more like an allowance to placate users coming from other systems than good practice. $\endgroup$ – Mr.Wizard Jun 22 '12 at 1:55
  • 2
    $\begingroup$ @Mr.Wizard Probably. $\endgroup$ – Brett Champion Jun 22 '12 at 2:35
  • $\begingroup$ Some date&time related functions also evaluate without [ ]: Yesterday, Today, Tomorrow & Now $\endgroup$ – Gustavo Delfino Jun 26 '18 at 13:32

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