1

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

~/.scalarc 
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560

1 Answers1

4

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.

Drew Faubion
  • 441
  • 3
  • 12
nadavwr
  • 1,820
  • 16
  • 20
  • BTW the startup time went from < 1 second to about four seconds. The .scalarc simply has import scala.collection.mutable – WestCoastProjects Nov 09 '13 at 22:51
  • @javadba The scala compiler spawned inside a REPL is actually initialized lazily, at first instruction. Your script is forcing it to initialize immediately, hence the delay. `scalac` unfortunately takes considerable amount of time to initialize, mainly because of classloading. – ghik Nov 09 '13 at 23:31
  • @ghik Thanks for that explanation. However when I run the same "import scala.collection.mutable" within a vanilla scala repl it comes up in maybe half the time. I ran/re-ran multiple times to be sure. – WestCoastProjects Nov 09 '13 at 23:49
  • @javadba Well, actually if you run it multiple times, it should get faster because classloading == reading from disk and subsequent invocations may use data cached by the OS. – ghik Nov 10 '13 at 00:20
  • @ghik I interleaved the scala with / without the .scalarc to avoid the contamination you mentioned. Feel free to experiment with this yourself to see same results: I supplied the one line in the .scalarc – WestCoastProjects Nov 10 '13 at 00:24
  • @nadavwr Please make this an "answer" and I will award it. – WestCoastProjects May 08 '14 at 23:23