The actual behaviour of using/include doesn’t seem to match the documentation, so clearly I do ot understand it. Here is a MWE to explain. In a clean environment (new empty folder and fresh REPL) create the following two modules and save as mytest.jl and myothertest.jl respectively:
module mytest
using myothertest
const VAR = 42
println(OTHERVAR)
export VAR
end # module mytest
module myothertest
const OTHERVAR = 999
export OTHERVAR
end # module myothertest
To run the module mytest I need to cd to the new folder and do push!(LOAD_PATH, pwd())
in the REPL. This all works. ‘999’ is printed in the REPL and I have access to both VAR and OTHERVAR.
Next I activate the package manager and at the Pkg prompt I do add CSV
(any registered package will do). Now when I try to run mytest as before (no changes to the LOAD_PATH or code whatsoever), it now fails with the error ERROR: LoadError: ArgumentError: Package myothertest not found in current path
.
So adding external repositories suddenly prevents Julia looking in the PWD even when it is part of the LOAD_PATH. This is unexpected behavior.
I can get to myothertest by adding include("myothertest.jl")
above the using myothertest
statement, but I don’t understand why Julia suddenly requires me to use include where it didn’t before. Am I doing something wrong? Is this normal behavior and if so, why?
3 posts - 3 participants