So I read the documentation for using
and import
in Julia. However what this does not tell me is how I should be using these two statements in practice (and, given the lack of orthogonality, this is not too easy).
Case in point: let's put the following trivial code in "myfile.jl"
:
module MyModule
f() = 1
export f
end
import .MyModule # or: using .MyModule
if I use
import
on the last line, thenf
is not exported toMain
namespace. However, when I change"myfile.jl"
(e.g. modifying the return value off
) and then re-include
it, the function is replaced (this is the behaviour I wish for). (Note that I could explicitlyimport .MyModule: f
, but this introduces unneeded redundancy; also, the real-life case will involve a long list of functions with long names. OK, I might also write a macro that usesnames(Main.MyModule)
, but I somehow feel that this ought to be simpler.)if I replace
import
byusing
, then this is reversed:f
is now exported, but changing anything in the module now requires re-starting the Julia interpreter.using both
import
andusing
exports only the first version off()
to the main namespace: when I update the code, only the first return value is used.
So my question is not about the behaviour of both statements import
and using
, which are documented (if not explained) in the linked page, but about the intent behind these. Why two statements when one would be enough? Why does one of these ignore all export
directives? In which case am I supposed, in practice, to use each statement?
(version is 1.1.0. Also, this runs on a system without easy Pkg
access, so I did not try Revise
yet.)