Clean workspace, plot pane, and console on re-run in Julia

For a “clear all” equivalent, you can use a module. If your script looks like this:

module MyModule
x = 3
end #module

Then, each time you re-run the script, you will see the message “WARNING: replacing module MyModule”, and any functions/variables that you created in there will be lost.
At the REPL, you can access the variables as e.g. MyModule.x.

If you want to compare the results before/after some change to the code, then re-name the module in your script and run it again. Now you have access to results of both runs, and can compute things like MyModule.x - MyNewModule.x.

Another option is to write functions instead of scripts.

2 Likes