函数调用问题请教

打算将自己的几个函数都放到一个文件a.jl中

module mymodule
function fun1()
    pass
end
function fun2()
    pass
end
end

在文件b.jl中调用a.jl的函数fun1
请问如何用简单的方式调用
目前我知道的是:

include("a.jl")
using.mymodule:fun1

不知道using后面为什么还要加个点.

在文档模块 · Julia中文文档
中也没看到有加点的用法啊

你的代码运行不了吧?

julia> module mymodule
           function fun1()
               1
           end
           function fun2()
               2
           end
       end
Main.mymodule

julia> mymodule.fun1()
1

是运行不了,pass只是一个示意
我的意思是b.jl的文件调用a.jl文件中的函数fun1
你这个在同一个文件里面吧?

你函数名后面没有括号。。。Julia没有using后面带点的语法。请再看一遍文档。

. 可以表示当前module里的module,然后就不会去全局找了,我记得是这样子?我先找找文档看能不能找到

using.mymoduleusing .mymodule

https://docs.julialang.org/en/v1/manual/modules/#Relative-and-absolute-module-paths-1

Here module Parent contains a submodule Utils , and code in Parent wants the contents of Utils to be visible. This is done by starting the using path with a period. Adding more leading periods moves up additional levels in the module hierarchy. For example using ..Utils would look for Utils in Parent 's enclosing module rather than in Parent itself.

1 个赞

加.才能运行啊


左上 a.jl 右上 b.jl

还是我自己文档看的不仔细,谢谢两位哥们的指导,谢谢!

好的,学习了,谢谢啦!