How to split a Scala script into multiple files

匿名 (未验证) 提交于 2019-12-03 08:41:19

问题:

Used as a scripting language, does Scala have some sort of include directive, or is there a way to launch a script from an other script ?

回答1:

The scala command has the :load filename command to load a Scala file interactively. Alternatively the scala command's -i filename argument can be used to preload the file.



回答2:

As of beginning of 2013, there seems to be no built-in support for multiple-file scripts.

There's one guy that implemented #include support for non-interactive scala scripts, by assembling and compiling the files in a prior stage (have not tried it yet).

Here is the blog post about it:

http://www.crosson.org/2012/01/simplifying-scala-scripts-adding.html

And the git repository:

https://github.com/dacr/bootstrap

I hope this, or something along the lines, get official some day, since the -i filename scala switch seems to apply only for the interactive console.

Until then a proper scripting language, like Ruby, might still remain the best option.



回答3:

Ammonite is an option. It implements scala (plus extensions) including import in scripts.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!