Clear workspace à la Pluto

A feature that I miss in Julia is the ability to clear my workspace. It is nice to be able to make sure that there is no global ghost-variable somewhere in your code, leading to it breaking if you restart your session. I frequently end up making such variables when prototyping code.

Pluto has shown me that it is possible. In Pluto, once you remove definitions, the variable/function is no longer defined. This is all without recompiling everything. If I am not mistaken, Pluto does this by defining a new main module.

In this discussion from 3-4 years ago, @jeff.bezanson stated that “… it should be possible to create a new module and “attach” the REPL to it. That seems like the right functionality for this.”

In the same discussion, @StefanKarpinski said that “… adding that functionality hasn’t been a high priority.”

So I was wondering - with Pluto having implemented a very functional solution, is this not the right time to make the functionality that would allow a user to clear the workspace?

1 Like

This is the issue for being able to change the module into which the REPL evaluates: REPL: allow attaching a module other than Main · Issue #22562 · JuliaLang/julia · GitHub. There have been some atttempts to implement this:

Once it’s possible to attach a new module to the REPL, then it should be easy to create a new Main module and attach that to the REPL, which should have the effect of clearing the workspace. What’s needed is for someone to roll up their sleeves and finish implementing this.