From 8c1bbafee4c68ccd158786deb4643d5a3074ce0d Mon Sep 17 00:00:00 2001 From: Philipp Haller Date: Fri, 2 Feb 2007 15:15:44 +0000 Subject: --- docs/examples/actors/BoundedBufferTest.scala | 34 ++++++++++++++-------------- docs/examples/actors/Joins.scala | 12 +++++----- 2 files changed, 23 insertions(+), 23 deletions(-) (limited to 'docs') diff --git a/docs/examples/actors/BoundedBufferTest.scala b/docs/examples/actors/BoundedBufferTest.scala index 5a04f7aafd..7585d8779a 100644 --- a/docs/examples/actors/BoundedBufferTest.scala +++ b/docs/examples/actors/BoundedBufferTest.scala @@ -2,29 +2,29 @@ package examples.actors import scala.actors.Actor._ -class BoundedBuffer[T](N: int) { - private case class Get - private case class Put(x: T) +object boundedbuffer { + class BoundedBuffer[T](N: int) { + private case class Get + private case class Put(x: T) - private val buffer = actor { - val buf = new Array[T](N) - var in = 0; var out = 0; var n = 0 - while(true) { - receive { - case Put(x) if n < N => - buf(in) = x; in = (in + 1) % N; n = n + 1; reply() - case Get() if n > 0 => - val r = buf(out); out = (out + 1) % N; n = n - 1; reply(r) + private val buffer = actor { + val buf = new Array[T](N) + var in = 0; var out = 0; var n = 0 + while(true) { + receive { + case Put(x) if n < N => + buf(in) = x; in = (in + 1) % N; n = n + 1; reply() + case Get() if n > 0 => + val r = buf(out); out = (out + 1) % N; n = n - 1; reply(r) + } } } - } - def put(x: T): Unit = buffer !? Put(x) + def put(x: T): Unit = buffer !? Put(x) - def get: T = (buffer !? Get()).asInstanceOf[T] -} + def get: T = (buffer !? Get()).asInstanceOf[T] + } -object BoundedBufferTest { def main(args: Array[String]) = { val buf = new BoundedBuffer[Int](1) buf.put(42) diff --git a/docs/examples/actors/Joins.scala b/docs/examples/actors/Joins.scala index 0a958bc768..7baad9504f 100644 --- a/docs/examples/actors/Joins.scala +++ b/docs/examples/actors/Joins.scala @@ -1,6 +1,6 @@ package examples.actors -import scala.actors.Actor +//import scala.actors.Actor import scala.actors.Actor._ abstract class Producer[T] { @@ -37,7 +37,7 @@ abstract class Producer[T] { } } - private val coordinator: Actor = actor { + private val coordinator /*: Actor*/ = actor { var continue = true while (continue) { receive { @@ -51,7 +51,7 @@ abstract class Producer[T] { } } - private val producer: Actor = actor { + private val producer = actor { receive { case Next => produceValues @@ -60,7 +60,7 @@ abstract class Producer[T] { } } -object Joins extends Application { +object producers extends Application { class Tree(val left: Tree, val elem: int, val right: Tree) def node(left: Tree, elem: int, right: Tree): Tree = new Tree(left, elem, right) @@ -101,7 +101,7 @@ object Joins extends Application { } } - actor { + //actor { Console.print("PreOrder:") for (val x <- new PreOrder(tree).iterator) Console.print(" "+x) Console.print("\nPostOrder:") @@ -109,5 +109,5 @@ object Joins extends Application { Console.print("\nInOrder:") for (val x <- new InOrder(tree).iterator) Console.print(" "+x) Console.print("\n") - } + //} } -- cgit v1.2.3