LS
I learn Scala using the "Scala Programming" by Odersky et al.
In the chapter on actors, I came across behavior that I cannot explain. More specifically, when you try to send a message to "yourself" (see also an example )
Entering the Scala shell:
scala> import scala.actors.Actor._ import scala.actors.Actor._ scala > self ! "Hello" scala > self.receive { case x => x }
But the last line does not return "with the expected answer":
resX:Any = hello
You need to do Ctrl-C to return the shell back to my input and return a message that:
Execution interrupted by signal. scala> self.receive {case x => x}
But actually the following works:
self ! "Hello" ; self.receive { case x => x }
My questions:
What's happening? Why does the first example not work, and the second does?!? I would like to understand the behavior of the shell a little better, since the authors of the book argue that using yourself as a recipient of actors' responses is a good debugging technique.
source share