Fixes recursion bug in disambiguate_in().
[ohcount] / test / src_dir / scala1.scala
1 import scala.actors.Actor
2
3 case object Ping
4 case object Pong
5 case object Stop
6
7 /**
8  * Ping class
9  */
10 class Ping(count: int, pong: Actor) extends Actor {
11   def act() {
12     var pingsLeft = count - 1
13     pong ! Ping
14     while (true) {
15       receive {
16         case Pong =>
17           if (pingsLeft % 1000 == 0)
18             Console.println("Ping: pong")
19           if (pingsLeft > 0) {
20             pong ! Ping
21             pingsLeft -= 1
22           } else {
23             Console.println("Ping: stop")
24             pong ! Stop
25             exit()
26           }
27       }
28     }
29   }
30 }
31
32 /**
33  * Pong class
34  */
35 class Pong extends Actor {
36   def act() {
37     var pongCount = 0
38     while (true) {
39       receive {
40         //pong back the ping
41         case Ping =>
42           if (pongCount % 1000 == 0)
43             Console.println("Pong: ping "+pongCount)
44           sender ! Pong
45           pongCount = pongCount + 1
46         //stop ping ponging
47         case Stop =>
48           Console.println("Pong: stop")
49           exit()
50       }
51     }
52   }
53 }
54
55 /*
56  * And this is the main application, playing a game of ping pong
57  */
58 object PingPong extends Application {
59   val pong = new Pong
60   val ping = new Ping(100000, pong)
61   ping.start
62   pong.start
63 }