Julia 自定义模块变量范围

发布于 2025-01-19 01:35:20 字数 573 浏览 3 评论 0原文

我开始用 Julia 编写我的第一个自定义模块。 我正在做的是将所有文件写入一个文件夹中,然后将它们导入到 ModuleName.jl 文件中,并最终编写一个执行预编译的 main() 函数的测试程序它调用我的自定义模块(我喜欢保持模块化的编程风格)。

问题是我认为我遗漏了使用 usingimport 关键字的一些内容。在我的测试文件中,我有以下几行:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜血染红嫁衣 2025-01-26 01:35:20

欢迎来到朱莉娅。
您是什么意思,预编译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 by using .ModuleName (note the dot). And remember to export the objects in ModuleName 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文