在Julia中声明主要功能/入口点 [英] Declaring main function/entry point in Julia

查看:119
本文介绍了在Julia中声明主要功能/入口点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有现成的或惯用的方式在Julia程序中声明入口点(即,等效于C中的main或Python中的if __name__ == "__main__"构造)?

Is there a ready or idiomatic way of declaring an entry point in a Julia program (i.e. the equivalent of main in C or the if __name__ == "__main__" construct in Python)?

这似乎是重要的功能,它可以编写较大的结构化代码,而这些结构化代码不会在交互模式下使用,但是我根本找不到任何有关如何在Julia中完成此操作的提示(如果有的话,可能的逃生路线可能是编写一个任意函数以用作main,然后在主模块末尾的顶层调用一次,但这并不美观,甚至效率不高. TIA.

This seems to be an important functionality in order to write larger pieces of structured code that won't be used in interactive mode but I couldn't find any hints as to how this is accomplished in Julia, if at all (a possible escape route could be writing an arbitrary function to serve as main and then calling it once on the top level at the end of the main module but that's not elegant and maybe not even efficient). TIA.

推荐答案

加载模块时,如果模块具有名为__init__的函数,则将调用该模块.有帮助吗?

When modules are loaded, if they have a function called __init__ it will be called. Does that help?

这篇关于在Julia中声明主要功能/入口点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆