How do I reload a module in an active Julia session after an edit?

The basis of this problem is the confluence of reloading a module, but not being able to redefine a thing in the module Main (see the documentation here) — that is at least until the new function workspace() was made available on July 13 2014. Recent versions of the 0.3 pre-release should have it.

Before workspace()

Consider the following simplistic module

module TstMod
export f

function f()
   return 1
end

end

Then use it….

julia> using TstMod

julia> f()
1

If the function f() is changed to return 2 and the module is reloaded, f is in fact updated. But not redefined in module Main.

julia> reload("TstMod")
Warning: replacing module TstMod

julia> TstMod.f()
2

julia> f()
1

The following warnings make the problem clear

julia> using TstMod
Warning: using TstMod.f in module Main conflicts with an existing identifier.

julia> using TstMod.f
Warning: ignoring conflicting import of TstMod.f into Main

Using workspace()

However, the new function workspace() clears Main preparing it for reloading TstMod

julia> workspace()

julia> reload("TstMod")

julia> using TstMod

julia> f()
2

Also, the previous Main is stored as LastMain

julia> whos()
Base                          Module
Core                          Module
LastMain                      Module
Main                          Module
TstMod                        Module
ans                           Nothing

julia> LastMain.f()
1

Leave a Comment