You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
Note that include does not substitute the contents at the place where it occurs, rather it evaluates them at the time the function is called. And AFAIU, in Julia 0.6 that happens to be Main unless the include happens while defining a module. Also, I don't think it's specific to __init__(). If you define another function in the same way and call it manually, you get the same error. On Julia master, every module gets its own include that evaluates into that module, so things work as expected there.
I'd like someone to verify, but I think the bottom line is that this is a known deficiency on 0.6 and fixed on master, so this issue could be closed.
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
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:
in main.jl:
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:
in main.jl:
The text was updated successfully, but these errors were encountered: