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.