Julia 从同级模块导入函数

Julia 从同级模块导入函数,julia,Julia,我有一个名为MAIN的包。在src文件夹中,我有以下文件: src/ MAIN.jl utils.jl models.jl 在MAIN.jl中,我有以下内容: module MAIN include("models.jl") include("utils.jl") end module models using ..utils export bar function bar() return foo() end end # module utils.

我有一个名为MAIN的包。在src文件夹中,我有以下文件:

src/
    MAIN.jl
    utils.jl
    models.jl
在MAIN.jl中,我有以下内容:

module MAIN

include("models.jl")
include("utils.jl")

end
module models
using ..utils

export bar
function bar()
   return foo()
end


end # module
utils.jl的内容是:

module utils
export foo
function foo()
    return 1
end
end
然后我想在models.jl文件中的函数中使用foo函数。 现在我有以下几点:

module MAIN

include("models.jl")
include("utils.jl")

end
module models
using ..utils

export bar
function bar()
   return foo()
end


end # module
但是当我运行
import MAIN
时,我得到以下错误:
LoadError:LoadError:UndefVarError:utils not defined


因此,在此设置中,如何将foo函数导入到
models.jl
文件中?

问题的原因是
import
调用的顺序错误<代码>导入语句按顺序求值,这意味着在求值
models.jl
文件时,
utils
模块未定义。要解决此问题,请使用以下导入顺序:

module MAIN

include("utils.jl")
include("models.jl")

end