diff options
author | Antonio Cunei <antonio.cunei@epfl.ch> | 2011-11-07 09:55:53 +0000 |
---|---|---|
committer | Antonio Cunei <antonio.cunei@epfl.ch> | 2011-11-07 09:55:53 +0000 |
commit | 44b32ff306ce4dfe171db00d6b37df65467f3f46 (patch) | |
tree | ccf6907387ed6a0304c8d3fc8b83f1964a05713f /docs/examples | |
parent | e196a153ccb69aed372b219ed18471a4fe29391e (diff) | |
download | scala-44b32ff306ce4dfe171db00d6b37df65467f3f46.tar.gz scala-44b32ff306ce4dfe171db00d6b37df65467f3f46.tar.bz2 scala-44b32ff306ce4dfe171db00d6b37df65467f3f46.zip |
Backport of r25948
Diffstat (limited to 'docs/examples')
35 files changed, 168 insertions, 168 deletions
diff --git a/docs/examples/actors/producers.scala b/docs/examples/actors/producers.scala index d3ff903f5b..80e5ae33d3 100644 --- a/docs/examples/actors/producers.scala +++ b/docs/examples/actors/producers.scala @@ -6,13 +6,13 @@ import scala.actors.Actor._ abstract class Producer[T] { /** A signal that the next value should be produced. */ - private val Next = new Object + private val Next = new Object /** A label for an undefined state of the iterators. */ private val Undefined = new Object /** A signal to stop the coordinator. */ - private val Stop = new Object + private val Stop = new Object protected def produce(x: T) { coordinator ! Some(x) @@ -53,10 +53,10 @@ abstract class Producer[T] { } private val producer: Actor = actor { - receive { - case Next => + receive { + case Next => produceValues - coordinator ! None + coordinator ! None } } } @@ -70,7 +70,7 @@ object producers extends Application { def tree = node(node(node(3), 4, node(6)), 8, node(node(9), 10, node(11))) class PreOrder(n: Tree) extends Producer[Int] { - def produceValues = traverse(n) + def produceValues = traverse(n) def traverse(n: Tree) { if (n != null) { produce(n.elem) @@ -81,7 +81,7 @@ object producers extends Application { } class PostOrder(n: Tree) extends Producer[Int] { - def produceValues = traverse(n) + def produceValues = traverse(n) def traverse(n: Tree) { if (n != null) { traverse(n.left) @@ -92,7 +92,7 @@ object producers extends Application { } class InOrder(n: Tree) extends Producer[Int] { - def produceValues = traverse(n) + def produceValues = traverse(n) def traverse(n: Tree) { if (n != null) { traverse(n.left) diff --git a/docs/examples/jolib/Ref.scala b/docs/examples/jolib/Ref.scala index 39c0123f09..5f655f16b1 100644 --- a/docs/examples/jolib/Ref.scala +++ b/docs/examples/jolib/Ref.scala @@ -12,7 +12,7 @@ import concurrent.SyncVar; import concurrent.jolib._; class Ref[a](init: a) extends Join { - + object get extends Synchr[a](this) { case class C() extends SyncVar[a]; } object set extends Synchr[unit](this) { case class C(x: a) extends SyncVar[unit]; } object state extends Asynchr(this) { case class C(x: a); } @@ -25,7 +25,7 @@ class Ref[a](init: a) extends Join { ); state(state.C(init)); - + def Get: a = get(get.C()); def Set(x: a): unit = set(set.C(x)); } diff --git a/docs/examples/jolib/parallelOr.scala b/docs/examples/jolib/parallelOr.scala index 4c4a852c4a..72d282bee3 100644 --- a/docs/examples/jolib/parallelOr.scala +++ b/docs/examples/jolib/parallelOr.scala @@ -13,27 +13,27 @@ import concurrent.SyncVar; /** Implementation in the join-calculus of a parallel OR. */ object or extends Join { - + object res extends Synchr[boolean](this) { case class C() extends SyncVar[boolean] }; object res1 extends Asynchr(this) { case class C(b: boolean); } object res2 extends Asynchr(this) { case class C(b: boolean); } object res1False extends Synchr[boolean](this) { case class C() extends SyncVar[boolean] }; object res2False extends Synchr[boolean](this) { case class C() extends SyncVar[boolean] }; - + rules( Pair(List(res, res1), { case List(r @ res.C(), res1.C(b)) => if (b) r.set(b) else r.set(res1False(res1False.C())) }), - + Pair(List(res, res2), { case List(r @ res.C(), res2.C(b)) => if (b) r.set(b) else r.set(res2False(res2False.C())) }), - + Pair(List(res1False, res2), { case List(r @ res1False.C(), res2.C(b)) => r.set(b) }), - + Pair(List(res2False, res1), { case List(r @ res2False.C(), res1.C(b)) => r.set(b) }) ); - + def apply(b1: => boolean, b2: => boolean): boolean = { concurrent.ops.spawn(res1(res1.C(b1))); concurrent.ops.spawn(res2(res2.C(b2))); @@ -42,7 +42,7 @@ object or extends Join { } */ object parallelOr { - + def main(args: Array[String]): unit = { def loop: boolean = { while (true) {}; true }; /* diff --git a/docs/examples/monads/callccInterpreter.scala b/docs/examples/monads/callccInterpreter.scala index 5b09b4c285..5b556bd8fa 100644 --- a/docs/examples/monads/callccInterpreter.scala +++ b/docs/examples/monads/callccInterpreter.scala @@ -14,7 +14,7 @@ object callccInterpreter { def showM(m: M[Value]): String = (m in id).toString(); - def callCC[A](h: (A => M[A]) => M[A]) = + def callCC[A](h: (A => M[A]) => M[A]) = M[A](c => h(a => M[A](d => c(a))) in c); type Name = String; @@ -30,7 +30,7 @@ object callccInterpreter { trait Value; case object Wrong extends Value { override def toString() = "wrong" - } + } case class Num(n: Int) extends Value { override def toString() = n.toString(); } @@ -70,7 +70,7 @@ object callccInterpreter { case Ccc(x, t) => callCC(k => interp(t, Pair(x, Fun(k)) :: e)) } - def test(t: Term): String = + def test(t: Term): String = showM(interp(t, List())); val term0 = App(Lam("x", Add(Var("x"), Var("x"))), Add(Con(10), Con(11))); diff --git a/docs/examples/monads/directInterpreter.scala b/docs/examples/monads/directInterpreter.scala index a80c9e4ed0..06fffba8e2 100644 --- a/docs/examples/monads/directInterpreter.scala +++ b/docs/examples/monads/directInterpreter.scala @@ -45,11 +45,11 @@ object directInterpreter { case App(f, t) => apply(interp(f, e), interp(t, e)) } - def test(t: Term): String = + def test(t: Term): String = showval(interp(t, List())); val term0 = App(Lam("x", Add(Var("x"), Var("x"))), Add(Con(10), Con(11))); - def main(args: Array[String]) = + def main(args: Array[String]) = System.out.println(test(term0)); } diff --git a/docs/examples/monads/simpleInterpreter.scala b/docs/examples/monads/simpleInterpreter.scala index 219b137c31..cde3a92dbb 100644 --- a/docs/examples/monads/simpleInterpreter.scala +++ b/docs/examples/monads/simpleInterpreter.scala @@ -22,7 +22,7 @@ object simpleInterpreter { trait Value; case object Wrong extends Value { override def toString() = "wrong" - } + } case class Num(n: Int) extends Value { override def toString() = n.toString(); } @@ -61,7 +61,7 @@ object simpleInterpreter { yield c } - def test(t: Term): String = + def test(t: Term): String = showM(interp(t, List())); val term0 = App(Lam("x", Add(Var("x"), Var("x"))), Add(Con(10), Con(11))); diff --git a/docs/examples/monads/stateInterpreter.scala b/docs/examples/monads/stateInterpreter.scala index 35568fb314..97f3335dab 100644 --- a/docs/examples/monads/stateInterpreter.scala +++ b/docs/examples/monads/stateInterpreter.scala @@ -7,7 +7,7 @@ object stateInterpreter { val tickS = new M(s => Pair((), s + 1)); case class M[A](in: State => Pair[A, State]) { - def bind[B](k: A => M[B]) = M[B]{ s0 => + def bind[B](k: A => M[B]) = M[B]{ s0 => val Pair(a, s1) = this in s0; k(a) in s1 } def map[B](f: A => B): M[B] = bind(x => unitM(f(x))); @@ -72,7 +72,7 @@ object stateInterpreter { yield c } - def test(t: Term): String = + def test(t: Term): String = showM(interp(t, List())); val term0 = App(Lam("x", Add(Var("x"), Var("x"))), Add(Con(10), Con(11))); diff --git a/docs/examples/parsing/ArithmeticParser.scala b/docs/examples/parsing/ArithmeticParser.scala index e8fbee4499..99cf7a5578 100644 --- a/docs/examples/parsing/ArithmeticParser.scala +++ b/docs/examples/parsing/ArithmeticParser.scala @@ -15,16 +15,16 @@ import scala.util.parsing.combinator.syntactical.StdTokenParsers * a term is a sequence of factors, separated by * or / * a factor is a parenthesized expression or a number * - * @author Adriaan Moors - */ -object arithmeticParser extends StdTokenParsers { + * @author Adriaan Moors + */ +object arithmeticParser extends StdTokenParsers { type Tokens = StdLexical ; val lexical = new StdLexical lexical.delimiters ++= List("(", ")", "+", "-", "*", "/") lazy val expr = term*("+" ^^^ {(x: int, y: int) => x + y} | "-" ^^^ {(x: int, y: int) => x - y}) lazy val term = factor*("*" ^^^ {(x: int, y: int) => x * y} | "/" ^^^ {(x: int, y: int) => x / y}) lazy val factor: Parser[int] = "(" ~> expr <~ ")" | numericLit ^^ (_.toInt) - + def main(args: Array[String]) { println( if (args.length == 1) { @@ -37,14 +37,14 @@ object arithmeticParser extends StdTokenParsers { } -object arithmeticParserDesugared extends StdTokenParsers { +object arithmeticParserDesugared extends StdTokenParsers { type Tokens = StdLexical ; val lexical = new StdLexical lexical.delimiters ++= List("(", ")", "+", "-", "*", "/") lazy val expr = chainl1(term, (keyword("+").^^^{(x: int, y: int) => x + y}).|(keyword("-").^^^{(x: int, y: int) => x - y})) lazy val term = chainl1(factor, (keyword("*").^^^{(x: int, y: int) => x * y}).|(keyword("/").^^^{(x: int, y: int) => x / y})) - lazy val factor: Parser[int] = keyword("(").~>(expr.<~(keyword(")"))).|(numericLit.^^(x => x.toInt)) - + lazy val factor: Parser[int] = keyword("(").~>(expr.<~(keyword(")"))).|(numericLit.^^(x => x.toInt)) + def main(args: Array[String]) { println( if (args.length == 1) { diff --git a/docs/examples/parsing/ArithmeticParsers.scala b/docs/examples/parsing/ArithmeticParsers.scala index 8fb3af7acb..62d7a61862 100644 --- a/docs/examples/parsing/ArithmeticParsers.scala +++ b/docs/examples/parsing/ArithmeticParsers.scala @@ -2,7 +2,7 @@ package examples.parsing import scala.util.parsing.combinator1.syntactical.StandardTokenParsers -object ArithmeticParsers extends StandardTokenParsers { +object ArithmeticParsers extends StandardTokenParsers { lexical.delimiters ++= List("(", ")", "+", "-", "*", "/") def expr: Parser[Any] = term ~ rep("+" ~ term | "-" ~ term) @@ -16,11 +16,11 @@ object ArithmeticParsers extends StandardTokenParsers { } } -object ArithmeticParsers1 extends StandardTokenParsers { +object ArithmeticParsers1 extends StandardTokenParsers { lexical.delimiters ++= List("(", ")", "+", "-", "*", "/") val reduceList: Int ~ List[String ~ Int] => Int = { - case i ~ ps => (i /: ps)(reduce) + case i ~ ps => (i /: ps)(reduce) } def reduce(x: Int, r: String ~ Int) = (r: @unchecked) match { @@ -45,11 +45,11 @@ class Expr case class BinOp(op: String, l: Expr, r: Expr) extends Expr case class Num(n: Int) extends Expr -object ArithmeticParsers2 extends StandardTokenParsers { +object ArithmeticParsers2 extends StandardTokenParsers { lexical.delimiters ++= List("(", ")", "+", "-", "*", "/") val reduceList: Expr ~ List[String ~ Expr] => Expr = { - case i ~ ps => (i /: ps)(reduce) + case i ~ ps => (i /: ps)(reduce) } def reduce(l: Expr, r: String ~ Expr) = BinOp(r._1, l, r._2) diff --git a/docs/examples/parsing/JSON.scala b/docs/examples/parsing/JSON.scala index bbba25f744..abfa242e9f 100644 --- a/docs/examples/parsing/JSON.scala +++ b/docs/examples/parsing/JSON.scala @@ -2,14 +2,14 @@ package examples.parsing import scala.util.parsing.combinator1.syntactical.StandardTokenParsers -object JSON extends StandardTokenParsers { +object JSON extends StandardTokenParsers { lexical.delimiters += ("{", "}", "[", "]", ":", ",") lexical.reserved += ("null", "true", "false") def obj : Parser[Any] = "{" ~ repsep(member, ",") ~ "}" def arr : Parser[Any] = "[" ~ repsep(value, ",") ~ "]" def member: Parser[Any] = ident ~ ":" ~ value - def value : Parser[Any] = ident | numericLit | obj | arr | + def value : Parser[Any] = ident | numericLit | obj | arr | "null" | "true" | "false" def main(args: Array[String]) { @@ -18,20 +18,20 @@ object JSON extends StandardTokenParsers { println(phrase(value)(tokens)) } } -object JSON1 extends StandardTokenParsers { +object JSON1 extends StandardTokenParsers { lexical.delimiters += ("{", "}", "[", "]", ":", ",") lexical.reserved += ("null", "true", "false") - def obj: Parser[Map[String, Any]] = + def obj: Parser[Map[String, Any]] = "{" ~> repsep(member, ",") <~ "}" ^^ (Map() ++ _) def arr: Parser[List[Any]] = - "[" ~> repsep(value, ",") <~ "]" + "[" ~> repsep(value, ",") <~ "]" - def member: Parser[(String, Any)] = + def member: Parser[(String, Any)] = ident ~ ":" ~ value ^^ { case name ~ ":" ~ value => (name -> value) } - def value: Parser[Any] = + def value: Parser[Any] = ident | numericLit ^^ (_.toInt) | obj | arr | "null" ^^^ null | "true" ^^^ true | "false" ^^^ false diff --git a/docs/examples/parsing/ListParser.scala b/docs/examples/parsing/ListParser.scala index 12805e5e50..59fc292c1d 100644 --- a/docs/examples/parsing/ListParser.scala +++ b/docs/examples/parsing/ListParser.scala @@ -14,7 +14,7 @@ object listParser { class ListParsers extends Parsers { type Elem = Char - + lazy val ident = rep1(elem("letter", isLetter), elem("letter or digit", isLetterOrDigit)) ^^ {cs => Id(mkString(cs))} lazy val number = chainl1(elem("digit", isDigit) ^^ (_ - '0'), success{(accum: Int, d: Int) => accum * 10 + d}) ^^ Num lazy val list = '(' ~> repsep(expr, ',') <~ ')' ^^ Lst diff --git a/docs/examples/parsing/ListParsers.scala b/docs/examples/parsing/ListParsers.scala index f503a0139f..b449c4a641 100644 --- a/docs/examples/parsing/ListParsers.scala +++ b/docs/examples/parsing/ListParsers.scala @@ -2,7 +2,7 @@ package examples.parsing import scala.util.parsing.combinator1.syntactical.StandardTokenParsers -object ListParsers extends StandardTokenParsers { +object ListParsers extends StandardTokenParsers { lexical.delimiters ++= List("(", ")", ",") def expr: Parser[Any] = "(" ~ exprs ~ ")" | ident | numericLit @@ -15,7 +15,7 @@ object ListParsers extends StandardTokenParsers { } } -object ListParsers1 extends StandardTokenParsers { +object ListParsers1 extends StandardTokenParsers { lexical.delimiters ++= List("(", ")", ",") def expr: Parser[Any] = "(" ~> exprs <~ ")" | ident | numericLit diff --git a/docs/examples/parsing/MiniML.scala b/docs/examples/parsing/MiniML.scala index ffc7c2ac92..f7f7172e8d 100644 --- a/docs/examples/parsing/MiniML.scala +++ b/docs/examples/parsing/MiniML.scala @@ -3,7 +3,7 @@ package examples.parsing import scala.util.parsing.combinator1.syntactical.StandardTokenParsers import scala.util.parsing.combinator1.syntactical.StandardTokenParsers -object MiniML extends StandardTokenParsers { +object MiniML extends StandardTokenParsers { lexical.delimiters += ("(", ")", ".", "=") lexical.reserved += ("lambda", "let", "in") @@ -30,7 +30,7 @@ case class Lambda(x: String, expr: Expr) extends Expr case class Apply(fun: Expr, arg: Expr) extends Expr case class Var(x: String) extends Expr -object MiniML1 extends StandardTokenParsers { +object MiniML1 extends StandardTokenParsers { lexical.delimiters += ("(", ")", ".", "=") lexical.reserved += ("lambda", "let", "in") @@ -41,7 +41,7 @@ object MiniML1 extends StandardTokenParsers { ) def simpleExpr: Parser[Expr] = ( ident ^^ { Var } - | "(" ~> expr <~ ")" + | "(" ~> expr <~ ")" ) def main(args: Array[String]) { diff --git a/docs/examples/parsing/lambda/Main.scala b/docs/examples/parsing/lambda/Main.scala index 81a175de77..165e82b670 100644 --- a/docs/examples/parsing/lambda/Main.scala +++ b/docs/examples/parsing/lambda/Main.scala @@ -27,8 +27,8 @@ object Main extends Application with TestParser { Console.println("Term: \n"+term) } - case Failure(msg, remainder) => Console.println("Failure: "+msg+"\n"+"Remainder: \n"+remainder.pos.longString) - case Error(msg, remainder) => Console.println("Error: "+msg+"\n"+"Remainder: \n"+remainder.pos.longString) + case Failure(msg, remainder) => Console.println("Failure: "+msg+"\n"+"Remainder: \n"+remainder.pos.longString) + case Error(msg, remainder) => Console.println("Error: "+msg+"\n"+"Remainder: \n"+remainder.pos.longString) } } } diff --git a/docs/examples/parsing/lambda/TestParser.scala b/docs/examples/parsing/lambda/TestParser.scala index 623b597337..d26589da1b 100644 --- a/docs/examples/parsing/lambda/TestParser.scala +++ b/docs/examples/parsing/lambda/TestParser.scala @@ -17,9 +17,9 @@ trait TestParser extends StdTokenParsers with ImplicitConversions with TestSynt lexical.reserved ++= List("unit", "let", "in", "if", "then", "else") lexical.delimiters ++= List("=>", "->", "==", "(", ")", "=", "\\", "+", "-", "*", "/") - + def name : Parser[Name] = ident ^^ Name - + // meaning of the arguments to the closure during subsequent iterations // (...(expr2 op1 expr1) ... op1 expr1) // ^a^^^ ^o^ ^b^^^ @@ -29,10 +29,10 @@ trait TestParser extends StdTokenParsers with ImplicitConversions with TestSynt def expr2 : Parser[Term] = chainl1(expr3, expr2, op2 ^^ {o => (a: Term, b: Term) => App(App(o, a), b)}) - + def expr3 : Parser[Term] = chainl1(expr4, expr3, op3 ^^ {o => (a: Term, b: Term) => App(App(o, a), b)}) - + def expr4 : Parser[Term] = ( "\\" ~> lambdas | ("let" ~> name) ~ ("=" ~> expr1) ~ ("in" ~> expr1) ^^ flatten3(Let) @@ -42,27 +42,27 @@ trait TestParser extends StdTokenParsers with ImplicitConversions with TestSynt def lambdas : Parser[Term] = name ~ ("->" ~> expr1 | lambdas) ^^ flatten2(Lam) - + def aexpr : Parser[Term] = ( numericLit ^^ (_.toInt) ^^ Lit | name ^^ Ref | "unit" ^^^ Unit() | "(" ~> expr1 <~ ")" ) - + def op1 : Parser[Term] = "==" ^^^ Ref(Name("==")) - + def op2 : Parser[Term] = ( "+" ^^^ Ref(Name("+")) | "-" ^^^ Ref(Name("-")) ) - + def op3 : Parser[Term] = ( "*" ^^^ Ref(Name("*")) | "/" ^^^ Ref(Name("/")) ) - + def parse(r: Reader[char]) : ParseResult[Term] = phrase(expr1)(new lexical.Scanner(r)) } diff --git a/docs/examples/parsing/lambda/TestSyntax.scala b/docs/examples/parsing/lambda/TestSyntax.scala index 531ae4bd54..7edca6ccdc 100644 --- a/docs/examples/parsing/lambda/TestSyntax.scala +++ b/docs/examples/parsing/lambda/TestSyntax.scala @@ -5,25 +5,25 @@ package examples.parsing.lambda * * @author Miles Sabin (adapted slightly by Adriaan Moors) */ -trait TestSyntax +trait TestSyntax { - trait Term - + trait Term + case class Unit extends Term { override def toString = "unit" } - + case class Lit(n: int) extends Term { override def toString = n.toString } - + case class Bool(b: boolean) extends Term { override def toString = b.toString } - + case class Name(name: String) extends Term { override def toString = name @@ -33,27 +33,27 @@ trait TestSyntax { def value = n } - + case class Lam(n: Name, l: Term) extends Term { override def toString = "(\\ "+n+" -> "+l+")" - } - + } + case class App(t1: Term, t2: Term) extends Term { override def toString = "("+t1+" "+t2+")" - } - + } + case class Let(n: Name, t1: Term, t2: Term) extends Term { override def toString = "let "+n+" = "+t1+" in "+t2 } - + case class If(c: Term, t1: Term, t2: Term) extends Term { override def toString = "if "+c+" then "+t1+" else "+t2 } - + trait PrimTerm extends Term { def apply(n: Lit) : Term @@ -68,7 +68,7 @@ trait TestSyntax { def apply(x: Lit) = new PrimTerm { def apply(y: Lit) = Lit(x.n-y.n) } } - + case class PrimMultiply extends PrimTerm { def apply(x: Lit) = new PrimTerm { def apply(y: Lit) = Lit(x.n*y.n) } diff --git a/docs/examples/pilib/elasticBuffer.scala b/docs/examples/pilib/elasticBuffer.scala index a0e8bb6a7c..5fec96ab6c 100644 --- a/docs/examples/pilib/elasticBuffer.scala +++ b/docs/examples/pilib/elasticBuffer.scala @@ -25,7 +25,7 @@ object elasticBuffer { /** * A buffer cell containing a value, ready to receive (o,r) from the right. */ - def Cl(i: Chan[String], l: MetaChan, + def Cl(i: Chan[String], l: MetaChan, o: Chan[String], r: MetaChan, content: String): Unit = choice ( o(content) * (Bl(i,l,o,r)), diff --git a/docs/examples/pilib/handover.scala b/docs/examples/pilib/handover.scala index 9725382c96..c9b6156c2c 100644 --- a/docs/examples/pilib/handover.scala +++ b/docs/examples/pilib/handover.scala @@ -32,7 +32,7 @@ object handoverRecursive { * Control center. */ def Control(talk1: Chan[unit], switch1: Switch, - gain1: Switch, lose1: Switch, + gain1: Switch, lose1: Switch, talk2: Chan[unit], switch2: Switch, gain2: Switch, lose2: Switch): unit = { @@ -108,7 +108,7 @@ object handoverCast { def Car(talk: Chan[Any], switch: Chan[Any]): unit = choice ( switch * (o => { - val Pair(t,s) = o.asInstanceOf[Pair[Chan[Any],Chan[Any]]]; + val Pair(t,s) = o.asInstanceOf[Pair[Chan[Any],Chan[Any]]]; Car(t, s) }), talk(()) * ( { @@ -122,7 +122,7 @@ object handoverCast { * Control center. */ def Control(talk1: Chan[Any], switch1: Chan[Any], - gain1: Chan[Any], lose1: Chan[Any], + gain1: Chan[Any], lose1: Chan[Any], talk2: Chan[Any], switch2: Chan[Any], gain2: Chan[Any], lose2: Chan[Any]): unit = { diff --git a/docs/examples/pilib/mobilePhoneProtocol.scala b/docs/examples/pilib/mobilePhoneProtocol.scala index 0805253ae0..e8c0ac1dc4 100644 --- a/docs/examples/pilib/mobilePhoneProtocol.scala +++ b/docs/examples/pilib/mobilePhoneProtocol.scala @@ -21,7 +21,7 @@ object mobilePhoneProtocol { case class HoCom() extends Message; // handover complete case class HoFail() extends Message; // handover fail case class ChRel() extends Message; // release - case class Voice(s: String) extends Message; // voice + case class Voice(s: String) extends Message; // voice case class Channel(n: Chan[Message]) extends Message; // channel def MobileSystem(in: Chan[String], out: Chan[String]): unit = { @@ -144,9 +144,9 @@ object mobilePhoneProtocol { } //***************** Entry function ******************// - + def main(args: Array[String]): unit = { - + def Producer(n: Int, put: Chan[String]): unit = { Thread.sleep(1 + random.nextInt(1000)); val msg = "object " + n; @@ -154,14 +154,14 @@ object mobilePhoneProtocol { System.out.println("Producer gave " + msg); Producer(n + 1, put) } - + def Consumer(get: Chan[String]): unit = { Thread.sleep(1 + random.nextInt(1000)); val msg = get.read; System.out.println("Consumer took " + msg); Consumer(get) } - + val put = new Chan[String]; val get = new Chan[String]; spawn < Producer(0, put) | Consumer(get) | MobileSystem(put, get) > diff --git a/docs/examples/pilib/piNat.scala b/docs/examples/pilib/piNat.scala index ee9e5ba1af..a1a0e682e1 100644 --- a/docs/examples/pilib/piNat.scala +++ b/docs/examples/pilib/piNat.scala @@ -4,7 +4,7 @@ import scala.concurrent.pilib._ /** Church encoding of naturals in the Pi-calculus */ object piNat extends Application { - + /** Locations of Pi-calculus natural */ class NatChan extends Chan[Triple[Chan[Unit], Chan[NatChan], Chan[NatChan]]] diff --git a/docs/examples/pilib/rwlock.scala b/docs/examples/pilib/rwlock.scala index 931f622f5a..bb1c26bdf2 100644 --- a/docs/examples/pilib/rwlock.scala +++ b/docs/examples/pilib/rwlock.scala @@ -250,7 +250,7 @@ object rwlock { def endRead = er.send def endWrite = ew.send - private def Reading(nr: int, nw: int): unit = + private def Reading(nr: int, nw: int): unit = if (nr == 0 && nw == 0) choice ( sr * (x => Reading(1, 0)), @@ -264,7 +264,7 @@ object rwlock { choice ( sr * (x => Reading(nr + 1, 0)), er * (x => Reading(nr - 1, 0)), - ww * (x => Reading(nr, 1)) + ww * (x => Reading(nr, 1)) ) else if (nr != 0 && nw != 0) choice ( diff --git a/docs/examples/pilib/scheduler.scala b/docs/examples/pilib/scheduler.scala index 9205ae3f0c..fd8fd52600 100644 --- a/docs/examples/pilib/scheduler.scala +++ b/docs/examples/pilib/scheduler.scala @@ -87,7 +87,7 @@ object scheduler { /** * A cell is modelled as a function that takes as parameters - * input and output channels and which returns nothing. + * input and output channels and which returns nothing. */ type Cell = (Chan[Unit], Chan[Unit]) => Unit diff --git a/docs/examples/pilib/semaphore.scala b/docs/examples/pilib/semaphore.scala index ed224890e2..951c90e8d4 100644 --- a/docs/examples/pilib/semaphore.scala +++ b/docs/examples/pilib/semaphore.scala @@ -65,7 +65,7 @@ object semaphore { println("b1"); Thread.sleep(1 + random.nextInt(100)); println("b2") - } ) + } ) } >; } } diff --git a/docs/examples/pilib/twoPlaceBuffer.scala b/docs/examples/pilib/twoPlaceBuffer.scala index f0f278317a..255f70ca06 100644 --- a/docs/examples/pilib/twoPlaceBuffer.scala +++ b/docs/examples/pilib/twoPlaceBuffer.scala @@ -16,7 +16,7 @@ object twoPlaceBuffer extends Application { def B1(x: A): Unit = choice ( out(x) * (B0), - in * (y => B2(x, y)) + in * (y => B2(x, y)) ) def B2(x: A, y: A): Unit = choice ( diff --git a/docs/examples/plugintemplate/src/plugintemplate/TemplatePlugin.scala b/docs/examples/plugintemplate/src/plugintemplate/TemplatePlugin.scala index b241072301..6cda37d4e3 100644 --- a/docs/examples/plugintemplate/src/plugintemplate/TemplatePlugin.scala +++ b/docs/examples/plugintemplate/src/plugintemplate/TemplatePlugin.scala @@ -16,7 +16,7 @@ class TemplatePlugin(val global: Global) extends Plugin { /** A short description of the plugin, read from the properties file */ val description = PluginProperties.pluginDescription - + /** @todo A description of the plugin's options */ override val optionsHelp = Some( " -P:"+ name +":option sets some option for this plugin") diff --git a/docs/examples/plugintemplate/src/plugintemplate/standalone/Main.scala b/docs/examples/plugintemplate/src/plugintemplate/standalone/Main.scala index ff1d1b50c5..19d2613649 100644 --- a/docs/examples/plugintemplate/src/plugintemplate/standalone/Main.scala +++ b/docs/examples/plugintemplate/src/plugintemplate/standalone/Main.scala @@ -5,7 +5,7 @@ import scala.tools.nsc.CompilerCommand import scala.tools.nsc.Settings /** An object for running the plugin as standalone application. - * + * * @todo: print, parse and apply plugin options !!! * ideally re-use the TemplatePlugin (-> runsAfter, optionsHelp, * processOptions, components, annotationChecker) instead of diff --git a/docs/examples/tcpoly/collection/HOSeq.scala b/docs/examples/tcpoly/collection/HOSeq.scala index a9414e3b3c..a6757b95ba 100644 --- a/docs/examples/tcpoly/collection/HOSeq.scala +++ b/docs/examples/tcpoly/collection/HOSeq.scala @@ -6,40 +6,40 @@ trait HOSeq { // values implementing this interface, in order to provide more performant ways of building that structure trait Accumulator[+coll[x], elT] { def += (el: elT): Unit - def result: coll[elT] + def result: coll[elT] } - - + + // Iterable abstracts over the type of its structure as well as its elements (see PolyP's Bifunctor) - // m[x] is intentionally unbounded: fold can then be defined nicely - // variance: if we write m[+x] instead of +m[+x], x is an invariant position because its enclosing type + // m[x] is intentionally unbounded: fold can then be defined nicely + // variance: if we write m[+x] instead of +m[+x], x is an invariant position because its enclosing type // is an invariant position -- should probably rule that out? trait Iterable[+m[+x], +t] { //def unit[a](orig: a): m[a] def iterator: Iterator[t] - + // construct an empty accumulator that will produce the same structure as this iterable, with elements of type t def accumulator[t]: Accumulator[m, t] - + def filter(p: t => Boolean): m[t] = { val buf = accumulator[t] val elems = elements while (elems.hasNext) { val x = elems.next; if (p(x)) buf += x } buf.result } - + def map[s](f: t => s): m[s] = { val buf = accumulator[s] val elems = elements while (elems.hasNext) buf += f(elems.next) buf.result } - + // flatMap is a more specialized map, it only works if the mapped function produces Iterable values, // which are then added to the result one by one // the compiler should be able to find the right accumulator (implicit buf) to build the result // to get concat, resColl = SingletonIterable, f = unit for SingletonIterable - def flatMap[resColl[x] <: Iterable[resColl, x], s](f: t => resColl[s])(implicit buf: Accumulator[resColl, s]): resColl[s] = { + def flatMap[resColl[x] <: Iterable[resColl, x], s](f: t => resColl[s])(implicit buf: Accumulator[resColl, s]): resColl[s] = { // TODO: would a viewbound for resColl[x] be better? // -- 2nd-order type params are not yet in scope in view bound val elems = elements @@ -48,9 +48,9 @@ trait HOSeq { while (elemss.hasNext) buf += elemss.next } buf.result - } + } } - + final class ListBuffer[A] { private var start: List[A] = Nil private var last: ::[A] = _ @@ -78,7 +78,7 @@ trait HOSeq { exported = !start.isEmpty start } - + /** Clears the buffer contents. */ def clear: unit = { @@ -97,13 +97,13 @@ trait HOSeq { } } } - + implicit def listAccumulator[elT]: Accumulator[List, elT] = new Accumulator[List, elT] { private[this] val buff = new ListBuffer[elT] def += (el: elT): Unit = buff += el def result: List[elT] = buff.toList } - + trait List[+t] extends Iterable[List, t] { def head: t def tail: List[t] @@ -111,16 +111,16 @@ trait HOSeq { def iterator: Iterator[t] = error("TODO") // construct an empty accumulator that will produce the same structure as this iterable, with elements of type t - def accumulator[t]: Accumulator[List, t] = error("TODO") + def accumulator[t]: Accumulator[List, t] = error("TODO") } - + // TODO: the var tl approach does not seem to work because subtyping isn't fully working yet final case class ::[+b](hd: b, private val tl: List[b]) extends List[b] { def head = hd def tail = if(tl==null) this else tl // hack override def isEmpty: boolean = false } - + case object Nil extends List[Nothing] { def isEmpty = true def head: Nothing = @@ -149,18 +149,18 @@ trait HOSeq { def filter(f: T=>Boolean): FilterResult def subseq(from: int, to: int): Subseq def flatMap[S <: Seq[K], K](f: T => S): S#Concat // legal? - def concat(others: Seq[T]): Concat + def concat(others: Seq[T]): Concat */ - + /*trait Iterator[t] { // @post hasAdvanced implies hasNext // model def hasAdvanced: Boolean - + def hasNext: Boolean // pure - + // @pre hasAdvanced def current: t // pure - + // @pre hasNext // @post hasAdvanced def advance: Unit diff --git a/docs/examples/tcpoly/monads/Monads.scala b/docs/examples/tcpoly/monads/Monads.scala index 5a966ce960..b6e3d5b9a8 100644 --- a/docs/examples/tcpoly/monads/Monads.scala +++ b/docs/examples/tcpoly/monads/Monads.scala @@ -6,18 +6,18 @@ trait Monads { * (>>=) :: m a -> (a -> m b) -> m b * return :: a -> m a * - * MonadTC encodes the above Haskell type class, + * MonadTC encodes the above Haskell type class, * an instance of MonadTC corresponds to a method dictionary. * (see http://lampwww.epfl.ch/~odersky/talks/wg2.8-boston06.pdf) * * Note that the identity (`this') of the method dictionary does not really correspond - * to the instance of m[x] (`self') that is `wrapped': e.g., unit does not use `self' (which + * to the instance of m[x] (`self') that is `wrapped': e.g., unit does not use `self' (which * corresponds to the argument of the implicit conversion that encodes an instance of this type class) */ // Option =:= [x] => Option[x] <: [x] => Any -// trait MonadTC[m <: [x] => Any, a] { +// trait MonadTC[m <: [x] => Any, a] { // MonadTC[m[x], a] x is a type parameter too -- should not write e.g., m[Int] here - trait MonadTC[m[x], a] { + trait MonadTC[m[x], a] { def unit[a](orig: a): m[a] // >>='s first argument comes from the implicit definition constructing this "method dictionary" @@ -32,7 +32,7 @@ trait Monads { */ trait OptionMonad extends Monads { // this implicit method encodes the Monad type class instance for Option - implicit def OptionInstOfMonad[a](self: Option[a]): MonadTC[Option, a] + implicit def OptionInstOfMonad[a](self: Option[a]): MonadTC[Option, a] = new MonadTC[Option, a] { def unit[a](orig: a) = Some(orig) def >>=[b](fun: a => Option[b]): Option[b] = self match { @@ -47,8 +47,8 @@ object main extends OptionMonad with Application { } -/* -trait MonadTC[m[x], a] requires m[x] { +/* +trait MonadTC[m[x], a] requires m[x] { def unit[a](orig: a): m[a] // >>='s first argument comes from the implicit definition constructing this "method dictionary" diff --git a/docs/examples/typeinf.scala b/docs/examples/typeinf.scala index 80980ebc9a..d4bc8bf3e1 100644 --- a/docs/examples/typeinf.scala +++ b/docs/examples/typeinf.scala @@ -69,14 +69,14 @@ object typeInfer { case Tycon(k, ts) => (List[Tyvar]() /: ts) ((tvs, t) => tvs union tyvars(t)) } - def tyvars(ts: TypeScheme): List[Tyvar] = + def tyvars(ts: TypeScheme): List[Tyvar] = tyvars(ts.tpe) diff ts.tyvars; def tyvars(env: Env): List[Tyvar] = (List[Tyvar]() /: env) ((tvs, nt) => tvs union tyvars(nt._2)) def mgu(t: Type, u: Type, s: Subst): Subst = Pair(s(t), s(u)) match { - case Pair(Tyvar(a), Tyvar(b)) if (a == b) => + case Pair(Tyvar(a), Tyvar(b)) if (a == b) => s case Pair(Tyvar(a), _) if !(tyvars(u) contains a) => s.extend(Tyvar(a), u) @@ -181,7 +181,7 @@ object typeInfer { yield Lam(x, t): Term ) ||| ( for ( - letid <- id if letid == "let"; + letid <- id if letid == "let"; x <- ident; _ <- wschr('='); t <- term; diff --git a/docs/examples/xml/phonebook/embeddedBook.scala b/docs/examples/xml/phonebook/embeddedBook.scala index 8ea9628212..3286485f0b 100644 --- a/docs/examples/xml/phonebook/embeddedBook.scala +++ b/docs/examples/xml/phonebook/embeddedBook.scala @@ -1,5 +1,5 @@ /* examples/phonebook/embeddedBook.scala */ -package phonebook +package phonebook object embeddedBook { @@ -8,14 +8,14 @@ object embeddedBook { val last = "Emir" val location = "work" - val embBook = + val embBook = <phonebook> <descr> - This is the <b>phonebook</b> of the + This is the <b>phonebook</b> of the {company} corporation. </descr> <entry> - <name>{ first+" "+last }</name> + <name>{ first+" "+last }</name> <phone where={ location }>+41 21 693 68 {val x = 60 + 7; x}</phone> </entry> </phonebook>; diff --git a/docs/examples/xml/phonebook/phonebook.scala b/docs/examples/xml/phonebook/phonebook.scala index 4813c2d20d..3c0dfbd837 100644 --- a/docs/examples/xml/phonebook/phonebook.scala +++ b/docs/examples/xml/phonebook/phonebook.scala @@ -2,14 +2,14 @@ package phonebook ; object phonebook { - val labPhoneBook = + val labPhoneBook = <phonebook> <descr> - This is the <b>phonebook</b> of the + This is the <b>phonebook</b> of the <a href="http://acme.org">ACME</a> corporation. </descr> <entry> - <name>Burak</name> + <name>Burak</name> <phone where="work"> +41 21 693 68 67</phone> <phone where="mobile">+41 79 602 23 23</phone> </entry> @@ -22,14 +22,14 @@ object phonebook { import scala.xml.{ Node, Text }; def add( phonebook:Node, newEntry:Node ):Node = phonebook match { - case <phonebook>{ ch @ _* }</phonebook> => + case <phonebook>{ ch @ _* }</phonebook> => <phonebook>{ ch }{ newEntry }</phonebook> } - val pb2 = - add( labPhoneBook, + val pb2 = + add( labPhoneBook, <entry> - <name>Kim</name> + <name>Kim</name> <phone where="work"> +41 21 111 11 11</phone> </entry> ); diff --git a/docs/examples/xml/phonebook/phonebook1.scala b/docs/examples/xml/phonebook/phonebook1.scala index 3a7a165202..316c6c1995 100644 --- a/docs/examples/xml/phonebook/phonebook1.scala +++ b/docs/examples/xml/phonebook/phonebook1.scala @@ -1,16 +1,16 @@ /* examples/phonebook/phonebook1.scala */ -package phonebook +package phonebook object phonebook1 { - val labPhoneBook = + val labPhoneBook = <phonebook> <descr> - This is the <b>phonebook</b> of the + This is the <b>phonebook</b> of the <a href="http://acme.org">ACME</a> corporation. </descr> <entry> - <name>Burak Emir</name> + <name>Burak Emir</name> <phone where="work">+41 21 693 68 67</phone> </entry> </phonebook>; diff --git a/docs/examples/xml/phonebook/phonebook2.scala b/docs/examples/xml/phonebook/phonebook2.scala index ba50379369..2a708daf7c 100644 --- a/docs/examples/xml/phonebook/phonebook2.scala +++ b/docs/examples/xml/phonebook/phonebook2.scala @@ -8,18 +8,18 @@ object phonebook2 { /** adds an entry to a phonebook */ def add( p: Node, newEntry: Node ): Node = p match { - case <phonebook>{ ch @ _* }</phonebook> => + case <phonebook>{ ch @ _* }</phonebook> => <phonebook>{ ch }{ newEntry }</phonebook> } - val pb2 = - add( phonebook1.labPhoneBook, + val pb2 = + add( phonebook1.labPhoneBook, <entry> - <name>Kim</name> + <name>Kim</name> <phone where="work">+41 21 111 11 11</phone> </entry> ); - def main( args: Array[String] ) = + def main( args: Array[String] ) = Console.println( pb2 ) } diff --git a/docs/examples/xml/phonebook/phonebook3.scala b/docs/examples/xml/phonebook/phonebook3.scala index 0dfae351b5..12f2deaa79 100644 --- a/docs/examples/xml/phonebook/phonebook3.scala +++ b/docs/examples/xml/phonebook/phonebook3.scala @@ -17,57 +17,57 @@ object phonebook3 { import xml.Utility.{trim,trimProper} //removes whitespace nodes, which are annoying in matches - for( val c <- ch ) yield + for( val c <- ch ) yield trimProper(c) match { // if the node is the particular entry we are looking for, return an updated copy - case x @ <entry><name>{ Text(Name) }</name>{ ch1 @ _* }</entry> => + case x @ <entry><name>{ Text(Name) }</name>{ ch1 @ _* }</entry> => var updated = false; val ch2 = for(c <- ch1) yield c match { // does it have the phone number? - case y @ <phone>{ _* }</phone> if y \ "@where" == Where => + case y @ <phone>{ _* }</phone> if y \ "@where" == Where => updated = true <phone where={ Where }>{ newPhone }</phone> - + case y => y - + } if( !updated ) { // no, so we add as first entry - + <entry> <name>{ Name }</name> <phone where={ Where }>{ newPhone }</phone> { ch1 } </entry> - + } else { // yes, and we changed it as we should - + <entry> { ch2 } </entry> - - } + + } // end case x @ <entry>... - + // other entries are copied without changing them - case x => + case x => x - + } } ; // for ... yield ... returns an Iterator[Node] - + // decompose phonebook, apply updates phonebook match { case <phonebook>{ ch @ _* }</phonebook> => <phonebook>{ copyOrChange( ch.iterator ) }</phonebook> } - + } - val pb2 = + val pb2 = change( phonebook1.labPhoneBook, "John", "work", "+41 55 555 55 55" ); val pp = new PrettyPrinter( 80, 5 ); diff --git a/docs/examples/xml/phonebook/verboseBook.scala b/docs/examples/xml/phonebook/verboseBook.scala index 611cf5370e..2dcb155480 100644 --- a/docs/examples/xml/phonebook/verboseBook.scala +++ b/docs/examples/xml/phonebook/verboseBook.scala @@ -1,24 +1,24 @@ /* examples/xml/phonebook/verboseBook.scala */ -package phonebook +package phonebook object verboseBook { - import scala.xml.{ UnprefixedAttribute, Elem, Node, Null, Text, TopScope } + import scala.xml.{ UnprefixedAttribute, Elem, Node, Null, Text, TopScope } - val pbookVerbose = + val pbookVerbose = Elem(null, "phonebook", Null, TopScope, Elem(null, "descr", Null, TopScope, - Text("This is a "), + Text("This is a "), Elem(null, "b", Null, TopScope, Text("sample")), Text("description") ), Elem(null, "entry", Null, TopScope, Elem(null, "name", Null, TopScope, Text("Burak Emir")), - Elem(null, "phone", new UnprefixedAttribute("where","work", Null), TopScope, + Elem(null, "phone", new UnprefixedAttribute("where","work", Null), TopScope, Text("+41 21 693 68 67")) ) ) - def main(args: Array[String]) = + def main(args: Array[String]) = Console.println( pbookVerbose ) } |