views:

119

answers:

2

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 ?

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 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.)

A: 

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.

dismal_denizen
+6  A: 

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

Randall Schulz
Thanks! That makes a lot more sense than it being the intended behaviour!
timday