Closed
Description
openedon Apr 12, 2018
for Julia 0.6
Easier to explain with examples.
But basically if you put an include
inside an __init__
,
then it does not have access to names that were added to the calling namespace by using
.
But if you put a using
at the top of the included file, then all is good.
(But that I feel should be an error).
Works
all in one file: main.jl
module Foo
export fooit
fooit()=println("IT was fooed")
end
module Bar
using Foo
__init__() = fooit()
end
using Bar
running that outputs "IT was fooed"
Doesn't work
Running main.jl gives
** InitError: LoadError: mUndefVarError: fooit not defined
while loading .../initstuff.jl **
in initstuff.jl:
fooit()
in main.jl:
module Foo
export fooit
fooit()=println("IT was fooed")
end
module Bar
using Foo
function __init__()
include("initstuff.jl")
end
end
using Bar
Works (but maybe shouldn't?)
I feel like this should be an error, as directly substituting the contents of initstuff.jl into __init__
would be an error.
in initstuff.jl:
using Foo
fooit()
in main.jl:
module Foo
export fooit
fooit()=println("IT was fooed")
end
module Bar
using Foo
function __init__()
include("initstuff.jl")
end
end
using Bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels