updated
authorChristian Urban <urbanc@in.tum.de>
Fri, 07 Dec 2018 12:17:27 +0000
changeset 242 e6b34f617915
parent 241 c650a91db720
child 243 9bb36426c781
updated
progs/lecture4.scala
progs/lecture5.scala
--- a/progs/lecture4.scala	Fri Dec 07 08:54:34 2018 +0000
+++ b/progs/lecture4.scala	Fri Dec 07 12:17:27 2018 +0000
@@ -308,6 +308,9 @@
   def next(q: A, c: C) : Set[A] = 
     Try(delta(q, c)) getOrElse Set[A]() 
 
+  def nexts(qs: Set[A], c: C) : Set[A] =
+    qs.flatMap(next(_, c))
+
   // depth-first version of accepts
   def search(q: A, s: List[C]) : Boolean = s match {
     case Nil => fins(q)
--- a/progs/lecture5.scala	Fri Dec 07 08:54:34 2018 +0000
+++ b/progs/lecture5.scala	Fri Dec 07 12:17:27 2018 +0000
@@ -20,7 +20,7 @@
 def peop(n: BigInt): Boolean = peop(n + 1) 
 
 val a = "foo"
-val b = "foo"
+val b = "bar"
 
 if (a == b || peop(0)) println("true") else println("false")
 
@@ -47,15 +47,15 @@
 val primes = generatePrimes(Stream.from(2))
 
 // the first 10 primes
-primes.take(10).toList
+primes.take(10).par.toList
 
 time_needed(1, primes.filter(_ > 100).take(3000).toList)
-time_needed(1, primes.filter(_ > 100).take(3000).toList)
+time_needed(1, primes.filter(_ > 100).take(1000).toList)
 
 // a stream of successive numbers
-Stream.from(2)
 
-Stream.from(2).take(10)
+Stream.from(2).print
+Stream.from(2).take(10).force
 Stream.from(2).take(10).print
 Stream.from(10).take(10).print
 
@@ -224,23 +224,6 @@
 }
 
 
-implicit def ParserOps[I<% Seq[_], T](p: Parser[I, T]) = new {
-  def | (q : => Parser[I, T]) = new AltParser[I, T](p, q)
-  def ==>[S] (f: => T => S) = new FunParser[I, T, S](p, f)
-  def ~[S] (q : => Parser[I, S]) = new SeqParser[I, T, S](p, q)
-}
-
-implicit def StringOps(s: String) = new {
-  def | (q : => Parser[String, String]) = new AltParser[String, String](s, q)
-  def | (r: String) = new AltParser[String, String](s, r)
-  def ==>[S] (f: => String => S) = new FunParser[String, String, S](s, f)
-  def ~[S] (q : => Parser[String, S]) = 
-    new SeqParser[String, String, S](s, q)
-  def ~ (r: String) = 
-    new SeqParser[String, String, String](s, r)
-}
-
-
 // atomic parsers  
 case class CharParser(c: Char) extends Parser[String, Char] {
   def parse(sb: String) =