Problems about using modules in same file

Cyan
Fri, 13 Jun 2025 15:23:40 +0000
New to Julia

I tried code like this

module moduleA
    function f1()
        println("test")
    end
end

module  moduleB
    function f2()
        moduleA.f1()
    end
end

moduleB.f2()

but it turned out ERROR: UndefVarError: `moduleA` not defined

I found that I can solve this problem via

module  moduleB
    using ..moduleA
    function f2()
        moduleA.f1()
    end
end

However, I am not sure about the mechanism behind it, and what if I have many modules like moduleB which need to import moduleA, is there any convenient way to import the moduleA in every moduleB ?

5 posts - 3 participants