2018 Update: Be sure to check all the responses, as the answer to this question has changed multiple times over the years. At the time of this update, the Revise.jl
answer is probably the best solution.
I have a file "/SomeAbsolutePath/ctbTestModule.jl", the contents of which are:
module ctbTestModule
export f1
f1(x) = x + 1
end
I fire up Julia in a terminal, which runs "~/.juliarc.jl". The startup code includes the line:
push!(LOAD_PATH, "/SomeAbsolutePath/")
Hence I can immediately type into the Julia console:
using ctbTestModule
to load my module. As expected f1(1)
returns 2
. Now I suddenly decide I want to edit f1
. I open up "/SomeAbsolutePath/ctbTestModule.jl" in an editor, and change the contents to:
module ctbTestModule
export f1
f1(x) = x + 2
end
I now try to reload the module in my active Julia session. I try
using ctbTestModule
but f1(1)
still returns 2
. Next I try:
reload("ctbTestModule")
as suggested here, but f1(1)
still returns 2
. Finally, I try:
include("/SomeAbsolutePath/ctbTestModule.jl")
as suggested here, which is not ideal since I have to type out the full absolute path since the current directory might not be "/SomeAbsolutePath". I get the warning message Warning: replacing module ctbTestModule
which sounds promising, but f1(1)
still returns 2
.
If I close the current Julia session, start a new one, and type in using ctbTestModule
, I now get the desired behaviour, i.e. f1(1)
returns 3
. But obviously I want to do this without re-starting Julia.
So, what am I doing wrong?
Other details: Julia v0.2 on Ubuntu 14.04.
workspace()
existed in Julia, I'd go so far as to accept miguelmorin's answer now instead of the previously accepted answer that has since become deprecated. – Irrawaddy