I am new to Julia but I have written a few lines of Julia and I am still juggling with this, and it feels like I still don’t get it or I am not doing something right. So start off, when I want to import a module using
using it seems I have two choices, I either
include the file source file that has that module so I can then call
using, or I append that directory to
LOAD_PATH? I don’t really understand the latter. Like will Julia look inside source files in the loaded directories? And I am not sure I would want to modify global variables to have my software run?
I have something like
push!(LOAD_PATH, ".\\Mod") from within
test.jl, that did not work. I would like to understand how this works, but still, I would like for my software to just run without touching global variables.
But the main thing I am concerned about is this below
#mod1.jl module Mod1 x = 1 end #mod2.jl include("mod1.jl") module Mod2 using Mod1 x = Mod1.x end #mod3.jl module Mod3 include("mod2.jl") end
julia mod2.jl works and
julia mod3.jl doesn’t (it cannot load
I have had a frustrating experience so far dealing with modules in Julia. Like, for instance, I tend to define
module_file.jl so I can include as follows
!isdefined(:module_file_jl) && include("module_file.jl")
I have the above all over my code base as to avoid type reloads that lead to run-time errors where equivalent types do not match (this was painful for a while) when I include
module_file.jl in several other files. But that trick solved the problem, but it certainly feels like a hack.
I have gone through the documentation for Modules, but I really need help here as this is bad (the way I am working on it). Thank you.