Julia 自定义模块变量范围
我开始用 Julia 编写我的第一个自定义模块。 我正在做的是将所有文件写入一个文件夹中,然后将它们导入到 ModuleName.jl
文件中,并最终编写一个执行预编译的 main()
函数的测试程序它调用我的自定义模块(我喜欢保持模块化的编程风格)。
问题是我认为我遗漏了使用 using
和 import
关键字的一些内容。在我的测试文件中,我有以下几行:
push!(LOAD_PATH,"./ModuleNameFolder")
using ModuleName
我认为如果使用 using
加载 ModuleName
的函数,则可以在没有显式 ModuleName.myfunct()
的情况下调用>,但只能通过myfunct()
,而事实并非如此。如果我省略 ModuleName
,编译器会抛出 UndefVarError
。 我做错了什么?我想将自定义模块的所有功能放在主范围内
I am starting writing my first custom module in Julia.
What I am doing is writing all the files in a folder, then import them in a ModuleName.jl
file and eventually writing a test program which executes a precompiled main()
function which calls my custom module (I like keeping a modular style of programming).
The problem is that I think I am missing something on the use of using
and import
keywords. In my test file I have the following lines:
push!(LOAD_PATH,"./ModuleNameFolder")
using ModuleName
I thought that functions of ModuleName
if loaded with using
could be called without explicit ModuleName.myfunct()
, but only through myfunct()
while this is not the case. If I omit the ModuleName
the compiler throws an UndefVarError
.
What am I doing wrong? I would like to bring all the functions of my custom module on the main scope
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
欢迎来到朱莉娅。
您是什么意思,
预编译main()函数
是什么意思?朱莉娅(Julia)中的测试通常在特定文件上设置,该文件在您使用的代码上的每个推送的每个推送中自动运行,用于托管代码。任何方法,尝试
include ./modulename
,然后使用.modulename (请注意点)。 并记住导出
modulename中的对象
您要直接提供。在我的教程上查看: https://syl1.gitbook.io/julia--/julia---/julia-in-julia----语言-a-concise-Tutorial/语言核/11-Developing-Julia-ackages
Welcome to Julia.
What do you mean by
precompiled main() function
? Tests in Julia are normally set on a specific file that is run automatically at each push of your code on the repository that you use to host the code.Any how, try
include ./ModuleName
followed byusing .ModuleName
(note the dot). And remember toexport
the objects inModuleName
that you want to make available directly.Have a look on my tutorial: https://syl1.gitbook.io/julia-language-a-concise-tutorial/language-core/11-developing-julia-packages