Startup script for scala REPL

2019-03-02 20:25发布

What is the name of startup script for the scala REPL. For example something along the lines of the following:

~/.scalarc 

标签: scala startup
1条回答
一夜七次
2楼-- · 2019-03-02 20:43

You could try something like:

$ alias scala='scala -i ~/.scalarc '

Note the trailing space—if you omit it your alias will disregard parameters.

Further use of 'scala' (once the alias is defined) will work as expected for REPL. If you use the alias for launching compiled programs, '~/.scalarc' will simply be ignored.

edit: It seems using '-i' in this way causes a significant slowdown.
The following, though somewhat convoluted (warning: bashism ahead), works faster:

$ scala -i <( cat ~/.scalarc foo.scala)

This concatenates your code (e.g. 'foo.scala') with '.scalarc' and evaluates everything on startup, leaving you at the REPL.
I don't think it's a satisfactory solution, but worth mentioning.

查看更多
登录 后发表回答