Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a Scala script into multiple files

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 ?

like image 305
Stephane Avatar asked Oct 07 '09 04:10

Stephane


3 Answers

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.

like image 75
Jim Ferrans Avatar answered Oct 31 '22 20:10

Jim Ferrans


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.

like image 21
Sebastian N. Avatar answered Oct 31 '22 20:10

Sebastian N.


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

like image 2
Marcin Avatar answered Oct 31 '22 19:10

Marcin