Is there a way to clear everything before starting in Mathematica?

前端 未结 3 1954
面向向阳花
面向向阳花 2021-02-04 06:03

In MATLAB there is the function clear to delete all current variables. This is very useful if you start something totally new and don\'t want to get conflicts with earl

3条回答
  •  余生分开走
    2021-02-04 06:39

    I just realized that you might not know that unlike MATLAB, Mathematica is designed to run as two separate processes: the Front End is the user interface, and lets you work with notebooks. The Kernel does the computations. You can quit the kernel without affecting the front end, or even start more than one kernel for different notebooks, or start a kernel on a remote computer and use it with a local front end.


    I believe that the only reliable way to clean everything is to Quit the kernel and re-start it (which is automatic). There are just too many things that can get modified apart from user variables/functions (including In/Out, loaded packages, system caches, etc.). So if you need a truly fresh start, I recommend Quit.

    For a "soft" reset, @yoda already mentioned ClearAll["Global`*"]. There's the << Utilities`CleanSlate` package, which automates a little bit more than this. You can read the package docs inside the AddOns\ExtraPackages\Utilities\CleanSlate.m file.

    In short, CleanSlate[] will attempt to take you back to the kernel state when the package was loaded. ClearInOut[] will clear In and Out to save memory.

    I haven't used this package in years (except for the ClearInOut[] functionality), as the Mathematica kernel starts up quickly on modern computers, so I just use Quit. So I can't tell you how well it works.

提交回复
热议问题