I was very interested to see the Contextual module REPL in the Julia 1.9 Highlights.
People in the past have asked about how to clear the REPL workspace, e.g.,
It seems like the contextual module REPL goes a long way to enable this. I’d be inclined to put the following function in my startup.jl
:
function temprepl()
name = gensym("REPL")
@eval module $name; import REPL; deactivate() = REPL.activate() end
@eval REPL.activate($name)
end
That way, temprepl()
activates a temporary workspace which can be “deleted” (caveat below) by running deactivate()
. A use case for this would be including some test file or to do some prototyping in the REPL without having to worry about polluting the workspace.
This still requires some forethought, as there’s no way to get an actual new Main
this way. Also, I don’t think the temporary workspace module would be garbage collected (it remains as a submodule of Main, as far as I understand).
Is this temprepl
a good idea, or an abuse of what the contextual module REPL is intended for? Any ideas for improvement? There’s probably no way to actually delete (garbage-collect) the temporary module after it is deactivated, right?