I'm guessing you are executing with just scala rather than compiling. The script does work if you compile it (and wrap it in an Application-trait singleton object):
import scala.actors.Actor._
object ActorTest extends Application {
val countActor = actor {
loop {
react {
case "how many?" => { println("I've got " + mailboxSize.toString + " messages in my mailbox.") }
}
}
}
countActor ! 1
countActor ! 2
countActor ! 3
countActor ! "how many?"
countActor ! "how many?"
countActor ! 4
countActor ! "how many?"
}
// vim: set ts=4 sw=4 et:
When I compile that, I get the following files:
- ActorTest$$anonfun$1$$anonfun$apply$2$$anonfun$apply$1.class
- ActorTest$$anonfun$1$$anonfun$apply$2.class
- ActorTest$$anonfun$1.class
- ActorTest$.class
- ActorTest.class
If I invoke it with scala -cp . ActorTest I get this:
ricoeur:~ tom$ scala -cp . ActorTest
I've got 6 messages in my mailbox.
I've got 5 messages in my mailbox.
I've got 4 messages in my mailbox.
^C
It sits and waits after the "I've got 4 messages in my mailbox" output until I Ctrl+C it.
Hope that helps.