diff options
Diffstat (limited to 'docs')
-rw-r--r-- | docs/examples/Parsers.scala | 10 | ||||
-rw-r--r-- | docs/examples/actors/producers.scala | 6 | ||||
-rw-r--r-- | docs/examples/fors.scala | 42 | ||||
-rw-r--r-- | docs/examples/iterators.scala | 2 | ||||
-rw-r--r-- | docs/examples/monads/callccInterpreter.scala | 12 | ||||
-rw-r--r-- | docs/examples/monads/errorInterpreter.scala | 12 | ||||
-rw-r--r-- | docs/examples/monads/simpleInterpreter.scala | 12 | ||||
-rw-r--r-- | docs/examples/monads/stateInterpreter.scala | 16 | ||||
-rw-r--r-- | docs/examples/parsers2.scala | 18 | ||||
-rw-r--r-- | docs/examples/typeinf.scala | 42 | ||||
-rw-r--r-- | docs/examples/xml/phonebook/phonebook3.scala | 2 |
11 files changed, 87 insertions, 87 deletions
diff --git a/docs/examples/Parsers.scala b/docs/examples/Parsers.scala index 15dc0ce9ef..b18d5d5188 100644 --- a/docs/examples/Parsers.scala +++ b/docs/examples/Parsers.scala @@ -39,7 +39,7 @@ abstract class Parsers { } def &&& [b](p: => Parser[b]): Parser[b] = - for (val _ <- this; val x <- p) yield x + for (_ <- this; x <- p) yield x } def succeed[a](x: a) = new Parser[a] { @@ -50,10 +50,10 @@ abstract class Parsers { rep1(p) ||| succeed(List()) def rep1[a](p: Parser[a]): Parser[List[a]] = - for (val x <- p; val xs <- rep(p)) yield x :: xs + for (x <- p; xs <- rep(p)) yield x :: xs def opt[a](p: Parser[a]): Parser[List[a]] = - (for (val x <- p) yield List(x)) ||| succeed(List()) + (for (x <- p) yield List(x)) ||| succeed(List()) } class Tokenizer(in: Iterator[char], delimiters: String) extends Iterator[String] { @@ -102,7 +102,7 @@ trait TokenParsers extends Parsers { trait CharParsers extends Parsers { def any: Parser[char] def chr(ch: char) = - for (val c <- any; c == ch) yield c + for (c <- any; if c == ch) yield c def chr(p: char => boolean) = - for (val c <- any; p(c)) yield c + for (c <- any; if p(c)) yield c } diff --git a/docs/examples/actors/producers.scala b/docs/examples/actors/producers.scala index c45ed63ed3..859de901e6 100644 --- a/docs/examples/actors/producers.scala +++ b/docs/examples/actors/producers.scala @@ -102,11 +102,11 @@ object producers extends Application { actor { Console.print("PreOrder:") - for (val x <- new PreOrder(tree).iterator) Console.print(" "+x) + for (x <- new PreOrder(tree).iterator) Console.print(" "+x) Console.print("\nPostOrder:") - for (val x <- new PostOrder(tree).iterator) Console.print(" "+x) + for (x <- new PostOrder(tree).iterator) Console.print(" "+x) Console.print("\nInOrder:") - for (val x <- new InOrder(tree).iterator) Console.print(" "+x) + for (x <- new InOrder(tree).iterator) Console.print(" "+x) Console.print("\n") } } diff --git a/docs/examples/fors.scala b/docs/examples/fors.scala index 3de4ba52b7..b36ac2b60f 100644 --- a/docs/examples/fors.scala +++ b/docs/examples/fors.scala @@ -16,7 +16,7 @@ object fors { printOlderThan20(xs.elements) def printOlderThan20(xs: Iterator[Person]): Iterator[String] = - for (val p <- xs; p.age > 20) yield p.name + for (p <- xs; if p.age > 20) yield p.name val persons = List( new Person("John", 40), @@ -24,20 +24,20 @@ object fors { ) def divisors(n: Int): List[Int] = - for (val i <- List.range(1, n+1); n % i == 0) yield i + for (i <- List.range(1, n+1); if n % i == 0) yield i def isPrime(n: Int) = divisors(n).length == 2 def findNums(n: Int): Iterator[Pair[Int, Int]] = - for (val i <- Iterator.range(1, n); - val j <- Iterator.range(1, i-1); - isPrime(i+j)) yield Pair(i, j) + for (i <- Iterator.range(1, n); + j <- Iterator.range(1, i-1); + if isPrime(i+j)) yield Pair(i, j) def sum(xs: List[Double]): Double = xs.foldLeft(0.0) { (x, y) => x + y } def scalProd(xs: List[Double], ys: List[Double]) = - sum(for(val Pair(x, y) <- xs zip ys) yield x * y) + sum(for((x, y) <- xs zip ys) yield x * y) type Lst = List[Any] @@ -67,29 +67,29 @@ object fors { ) def findAuthor(books: Lst) = - for (val Elem(_, "book", _, _, book @ _*) <- books; - val Elem(_, "title", _, _, Text(title)) <- book.toList; - (title indexOf "Program") >= 0; - val Elem(_, "author", _, _, Text(author)) <- List(book)) yield author + for (Elem(_, "book", _, _, book @ _*) <- books; + Elem(_, "title", _, _, Text(title)) <- book.toList; + if (title indexOf "Program") >= 0; + Elem(_, "author", _, _, Text(author)) <- List(book)) yield author - for (val Elem(_, "book", _, _, book @ _*) <- books; - val Elem(_, "author", _, _, Text(author)) <- book.toList; - author startsWith "Ullman"; - val Elem(_, "title", _, _, Text(title)) <- List(book)) yield title + for (Elem(_, "book", _, _, book @ _*) <- books; + Elem(_, "author", _, _, Text(author)) <- book.toList; + if author startsWith "Ullman"; + Elem(_, "title", _, _, Text(title)) <- List(book)) yield title removeDuplicates( - for (val Elem(_, "book", _, _, b1 @ _* ) <- books; - val Elem(_, "book", _, _, b2 @ _*) <- books; - b1 != b2; - val Elem(_, "author", _, _, Text(a1)) <- b1.toList; - val Elem(_, "author", _, _, Text(a2)) <- b2.toList; - a1 == a2) yield Pair(a1, a2)) + for (Elem(_, "book", _, _, b1 @ _* ) <- books; + Elem(_, "book", _, _, b2 @ _*) <- books; + if b1 != b2; + Elem(_, "author", _, _, Text(a1)) <- b1.toList; + Elem(_, "author", _, _, Text(a2)) <- b2.toList; + if a1 == a2) yield Pair(a1, a2)) def removeDuplicates[a](xs: List[a]): List[a] = if (xs.isEmpty) xs else - xs.head :: removeDuplicates(for (val x <- xs.tail; x != xs.head) yield x) + xs.head :: removeDuplicates(for (x <- xs.tail; if x != xs.head) yield x) def main(args: Array[String]) = { Console.print("Persons over 20:") diff --git a/docs/examples/iterators.scala b/docs/examples/iterators.scala index c0bfb91cef..b390f4007a 100644 --- a/docs/examples/iterators.scala +++ b/docs/examples/iterators.scala @@ -4,7 +4,7 @@ object iterators { def Array(elems: Double*): Array[Double] = { val ar = new Array[Double](elems.length) - for (val i <- Iterator.range(0, elems.length)) + for (i <- Iterator.range(0, elems.length)) ar(i) = elems(i) ar } diff --git a/docs/examples/monads/callccInterpreter.scala b/docs/examples/monads/callccInterpreter.scala index a0b16738c6..b184b4592e 100644 --- a/docs/examples/monads/callccInterpreter.scala +++ b/docs/examples/monads/callccInterpreter.scala @@ -58,14 +58,14 @@ object callccInterpreter { def interp(t: Term, e: Environment): M[Value] = t match { case Var(x) => lookup(x, e) case Con(n) => unitM(Num(n)) - case Add(l, r) => for (val a <- interp(l, e); - val b <- interp(r, e); - val c <- add(a, b)) + case Add(l, r) => for (a <- interp(l, e); + b <- interp(r, e); + c <- add(a, b)) yield c case Lam(x, t) => unitM(Fun(a => interp(t, Pair(x, a) :: e))) - case App(f, t) => for (val a <- interp(f, e); - val b <- interp(t, e); - val c <- apply(a, b)) + case App(f, t) => for (a <- interp(f, e); + b <- interp(t, e); + c <- apply(a, b)) yield c case Ccc(x, t) => callCC(k => interp(t, Pair(x, Fun(k)) :: e)) } diff --git a/docs/examples/monads/errorInterpreter.scala b/docs/examples/monads/errorInterpreter.scala index 4edb5caf88..536b7a152f 100644 --- a/docs/examples/monads/errorInterpreter.scala +++ b/docs/examples/monads/errorInterpreter.scala @@ -61,14 +61,14 @@ object errorInterpreter { def interp(t: Term, e: Environment): M[Value] = t match { case Var(x) => lookup(x, e) case Con(n) => unitM(Num(n)) - case Add(l, r) => for (val a <- interp(l, e); - val b <- interp(r, e); - val c <- add(a, b)) + case Add(l, r) => for (a <- interp(l, e); + b <- interp(r, e); + c <- add(a, b)) yield c case Lam(x, t) => unitM(Fun(a => interp(t, Pair(x, a) :: e))) - case App(f, t) => for (val a <- interp(f, e); - val b <- interp(t, e); - val c <- apply(a, b)) + case App(f, t) => for (a <- interp(f, e); + b <- interp(t, e); + c <- apply(a, b)) yield c } diff --git a/docs/examples/monads/simpleInterpreter.scala b/docs/examples/monads/simpleInterpreter.scala index d728c620cf..0707c40d06 100644 --- a/docs/examples/monads/simpleInterpreter.scala +++ b/docs/examples/monads/simpleInterpreter.scala @@ -50,14 +50,14 @@ object simpleInterpreter { def interp(t: Term, e: Environment): M[Value] = t match { case Var(x) => lookup(x, e) case Con(n) => unitM(Num(n)) - case Add(l, r) => for (val a <- interp(l, e); - val b <- interp(r, e); - val c <- add(a, b)) + case Add(l, r) => for (a <- interp(l, e); + b <- interp(r, e); + c <- add(a, b)) yield c case Lam(x, t) => unitM(Fun(a => interp(t, Pair(x, a) :: e))) - case App(f, t) => for (val a <- interp(f, e); - val b <- interp(t, e); - val c <- apply(a, b)) + case App(f, t) => for (a <- interp(f, e); + b <- interp(t, e); + c <- apply(a, b)) yield c } diff --git a/docs/examples/monads/stateInterpreter.scala b/docs/examples/monads/stateInterpreter.scala index 593f2d9e3e..499d97e418 100644 --- a/docs/examples/monads/stateInterpreter.scala +++ b/docs/examples/monads/stateInterpreter.scala @@ -49,26 +49,26 @@ object stateInterpreter { } def add(a: Value, b: Value): M[Value] = Pair(a, b) match { - case Pair(Num(m), Num(n)) => for (val _ <- tickS) yield Num(m + n) + case Pair(Num(m), Num(n)) => for (_ <- tickS) yield Num(m + n) case _ => unitM(Wrong) } def apply(a: Value, b: Value): M[Value] = a match { - case Fun(k) => for (val _ <- tickS; val c <- k(b)) yield c + case Fun(k) => for (_ <- tickS; c <- k(b)) yield c case _ => unitM(Wrong) } def interp(t: Term, e: Environment): M[Value] = t match { case Var(x) => lookup(x, e) case Con(n) => unitM(Num(n)) - case Add(l, r) => for (val a <- interp(l, e); - val b <- interp(r, e); - val c <- add(a, b)) + case Add(l, r) => for (a <- interp(l, e); + b <- interp(r, e); + c <- add(a, b)) yield c case Lam(x, t) => unitM(Fun(a => interp(t, Pair(x, a) :: e))) - case App(f, t) => for (val a <- interp(f, e); - val b <- interp(t, e); - val c <- apply(a, b)) + case App(f, t) => for (a <- interp(f, e); + b <- interp(t, e); + c <- apply(a, b)) yield c } diff --git a/docs/examples/parsers2.scala b/docs/examples/parsers2.scala index 8ae5d50ea5..b8a497c904 100644 --- a/docs/examples/parsers2.scala +++ b/docs/examples/parsers2.scala @@ -15,27 +15,27 @@ object parsers2 { def ident: Parser[Tree] = for ( - val c: char <- chr(isLetter); - val cs: List[char] <- rep(chr(isLetterOrDigit)) + c: char <- chr(isLetter); + cs: List[char] <- rep(chr(isLetterOrDigit)) ) yield Id((c :: cs).mkString("", "", "")) def number: Parser[Tree] = for ( - val d: char <- chr(isDigit); - val ds: List[char] <- rep(chr(isDigit)) + d: char <- chr(isDigit); + ds: List[char] <- rep(chr(isDigit)) ) yield Num(((d - '0') /: ds) ((x, digit) => x * 10 + digit - '0')) def list: Parser[Tree] = for ( - val _ <- chr('('); - val es <- listElems ||| succeed(List()); - val _ <- chr(')') + _ <- chr('('); + es <- listElems ||| succeed(List()); + _ <- chr(')') ) yield Lst(es) def listElems: Parser[List[Tree]] = for ( - val x <- expr; - val xs <- chr(',') &&& listElems ||| succeed(List()) + x <- expr; + xs <- chr(',') &&& listElems ||| succeed(List()) ) yield x :: xs def expr: Parser[Tree] = diff --git a/docs/examples/typeinf.scala b/docs/examples/typeinf.scala index f2dd252ff7..da9ba9384c 100644 --- a/docs/examples/typeinf.scala +++ b/docs/examples/typeinf.scala @@ -163,55 +163,55 @@ object typeInfer { /** identifiers or keywords */ def id: Parser[String] = for ( - val c: char <- rep(chr(' ')) &&& chr(isLetter); - val cs: List[char] <- rep(chr(isLetterOrDigit)) + c: char <- rep(chr(' ')) &&& chr(isLetter); + cs: List[char] <- rep(chr(isLetterOrDigit)) ) yield (c :: cs).mkString("", "", "") /** Non-keyword identifiers */ def ident: Parser[String] = - for (val s <- id; s != "let" && s != "in") yield s + for (s <- id; if s != "let" && s != "in") yield s /** term = '\' ident '.' term | term1 {term1} | let ident "=" term in term */ def term: Parser[Term] = ( ( for ( - val _ <- wschr('\\'); - val x <- ident; - val _ <- wschr('.'); - val t <- term) + _ <- wschr('\\'); + x <- ident; + _ <- wschr('.'); + t <- term) yield Lam(x, t): Term ) ||| ( for ( - val letid <- id; letid == "let"; - val x <- ident; - val _ <- wschr('='); - val t <- term; - val inid <- id; inid == "in"; - val c <- term) + letid <- id; if letid == "let"; + x <- ident; + _ <- wschr('='); + t <- term; + inid <- id; if inid == "in"; + c <- term) yield Let(x, t, c) ) ||| ( for ( - val t <- term1; - val ts <- rep(term1)) + t <- term1; + ts <- rep(term1)) yield (t /: ts)((f, arg) => App(f, arg)) ) ) /** term1 = ident | '(' term ')' */ def term1: Parser[Term] = ( - ( for (val s <- ident) + ( for (s <- ident) yield Var(s): Term ) ||| ( for ( - val _ <- wschr('('); - val t <- term; - val _ <- wschr(')')) + _ <- wschr('('); + t <- term; + _ <- wschr(')')) yield t ) ) /** all = term ';' */ def all: Parser[Term] = for ( - val t <- term; - val _ <- wschr(';')) + t <- term; + _ <- wschr(';')) yield t } diff --git a/docs/examples/xml/phonebook/phonebook3.scala b/docs/examples/xml/phonebook/phonebook3.scala index cd02490696..0965b16558 100644 --- a/docs/examples/xml/phonebook/phonebook3.scala +++ b/docs/examples/xml/phonebook/phonebook3.scala @@ -41,7 +41,7 @@ object phonebook3 { /** walks through tree, returns changed/copied updated tree */ def copyOrChange ( ch: Iterator[Node] ):List[Node] = { - for( val c <- ch ) yield c match { + for(c <- ch ) yield c match { case x @ <entry>{ ch1 @ _* }</entry> if hasName(x) => val it = ch1.elements; |