What is scala -i command-line option supposed to do?
I'm finding the scala '-i' command line option quite useful for running some scala code and then dumping me into an interactive shell so I can prod/inspect the things it defined.
One thing which completely mystifies me though: why does it load and run the script twice开发者_如何学JAVA ?
For example, given file test.scala containing the cannonical
println("Hello world")
running
scala -i test.scala
produces:
$ scala -i test.scala
Loading test.scala...
Hello world
Loading test.scala...
Hello world
Welcome to Scala version 2.7.5final (Java HotSpot(TM) Client VM, Java 1.6.0_12).
Type in expressions to have them evaluated.
Type :help for more information.
scala>
Obviously running that twice wasn't too much of a headache, but it's annoying for scripts which take a while to run (I'm using the [Project Euler]((https://projecteuler.net) problems to learn scala)
I assume I'm misunderstanding the intent or usage of the -i option somehow... how do I get my script file run just once ?
(FWIW, I'm on Debian/Lenny with the scala package from Squeeze.)
The double-loading of files given to the -i option is a well-known bug in Scala 2.7. It is long fixed in the 2.8 development trunk.
RRS
The scala manual page says that the -i option "requests that a file be pre-loaded. It is only meaningful for interactive shells". It seems that people who are not shells are not supposed to use it.
精彩评论