khanh
khanh

Reputation: 635

Other modules not visible from module

I am currently learning Julia (1 week, finished the first 15 sections in https://raw.githubusercontent.com/JuliaLang/docs.julialang.org/assets/julia-1.6.1.pdf).

Currently don't understand how module in Julia works.

Minimal reproducible example:

module ModuleA
    foo = 3
end

module ModuleB
    bar = ModuleA.foo
end

println(ModuleB.bar)

How does it give the error ERROR: LoadError: UndefVarError: ModuleA not defined at line bar = ModuleA.foo?

Thanks in advance!

Upvotes: 2

Views: 114

Answers (1)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42234

The ModuleA got defined within the module Main so in your case it needs to be:

bar = Main.ModuleA.foo

Or you can import ModuleA as:

module ModuleB
    using Main.ModuleA
    bar = ModuleA.foo
end

Upvotes: 3

Related Questions