Scala Actor in script mode -
i'm trying go through chapter 9 of programming in scala, found actor sample code not run in script mode.
the code simple:
// testactor.scala import scala.actors.actor class redford extends actor { def act() { println("a lot of acting is, paying attention.") } } val robert = new redford robert.start
but when run scala testactor.scala
, nothing happens, program exit before redford class print anything.
but if use following code compile , run, works fine, prints message expected.
// testactorcompiled.scala import scala.actors.actor class redford extends actor { def act() { println("a lot of acting is, paying attention.") } } object main { def main (args: array[string]) { val robert = new redford robert.start } }
it seems when program run in script mode, exit before actor doing anything.
why happens? , how make program no exit before actor.act()
done when program running in script mode?
update:
i'm using scala 2.8.1.final
tested on 2.8.1.final
. strange thing. first time run failed with:
could not connect compilation daemon. exception in thread "main" java.lang.exception: fsc failure @ scala.tools.nsc.compilesocket.fatal(compilesocket.scala:50) @ scala.tools.nsc.compilesocket.getport(compilesocket.scala:122) @ scala.tools.nsc.compilesocket.getsock$1(compilesocket.scala:152) @ scala.tools.nsc.compilesocket.getorcreatesocket(compilesocket.scala:170) @ scala.tools.nsc.scriptrunner$.compilewithdaemon(scriptrunner.scala:145) @ scala.tools.nsc.scriptrunner$.compile$1(scriptrunner.scala:197) @ scala.tools.nsc.scriptrunner$.withcompiledscript(scriptrunner.scala:225) @ scala.tools.nsc.scriptrunner$.runscript(scriptrunner.scala:265) @ scala.tools.nsc.maingenericrunner$.main(maingenericrunner.scala:91) @ scala.tools.nsc.maingenericrunner.main(maingenericrunner.scala)
the second time passed successfully:
>scala testactor.scala lot of acting is, paying attention.
Comments
Post a Comment