自我演员挂在repl

Ste*_*haw 0 scala actor

我正在遵循Scala版本1 30.3(p589)中的编程.在那里它解释了你可以使用'self'作为当前线程的actor来调试repl中的actor.但是,当我跟随Scala 2.9.1时,线程会在接收时挂起.

$ scala -unchecked -deprecation
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import scala.actors.Actor._
import scala.actors.Actor._

scala> self ! "hi"

scala> self.receive { case a => a }
[hangs - should be "res1: Any = hi"]
Run Code Online (Sandbox Code Playgroud)

我检查Scala 2.7.7,它按预期工作.如何使用Scala 2.9.1?

Ken*_*ida 5

因为2.9.1 REPL每个输入运行不同的线程.

请参阅 https://gist.github.com/1324774

请使用"-Yrepl-sync"选项,比每个输入相同的Thread.

https://lampsvn.epfl.ch/trac/scala/browser/scala/tags/R_2_9_1_final/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala#L149