--- a/progs/lecture3.scala Tue Nov 19 00:40:27 2019 +0000
+++ b/progs/lecture3.scala Tue Nov 19 06:38:10 2019 +0000
@@ -47,7 +47,8 @@
if (n == 0) ()
else {
println(s" Visiting: $n $url")
- for (u <- get_all_URLs(get_page(url))) crawl(u, n - 1)
+ val page = get_page(url)
+ for (u <- get_all_URLs(page)) crawl(u, n - 1)
}
}
@@ -121,8 +122,9 @@
def search(xs: List[Int]) : Boolean = xs match {
case Nil => true
- case (x::xs) =>
- if (xs.length < x) true else moves(xs, x).exists(search(_))
+ case x::xs =>
+ if (xs.length < x) true
+ else moves(xs, x).exists(search(_))
}
@@ -138,7 +140,7 @@
search(List(3,5,1,0,0,0,0,0,0,0,0,1))
// generates *all* jump tours
-// if we are only interested in the shortes one, we could
+// if we are only interested in the shortest one, we could
// shortcircut the calculation and only return List(x) in
// case where xs.length < x, because no tour can be shorter
// than 1
@@ -146,7 +148,7 @@
def jumps(xs: List[Int]) : List[List[Int]] = xs match {
case Nil => Nil
- case (x::xs) => {
+ case x::xs => {
val children = moves(xs, x)
val results = children.map(cs => jumps(cs).map(x :: _)).flatten
if (xs.length < x) List(x)::results else results
@@ -180,7 +182,7 @@
//========================
-abstract class Colour
+sealed abstract class Colour
case object Red extends Colour
case object Green extends Colour
case object Blue extends Colour
@@ -196,7 +198,7 @@
// ... a tiny bit more useful: Roman Numerals
-abstract class RomanDigit
+sealed abstract class RomanDigit
case object I extends RomanDigit
case object V extends RomanDigit
case object X extends RomanDigit
@@ -269,7 +271,7 @@
// trees
-abstract class Exp
+sealed abstract class Exp
case class N(n: Int) extends Exp // for numbers
case class Plus(e1: Exp, e2: Exp) extends Exp
case class Times(e1: Exp, e2: Exp) extends Exp
@@ -314,7 +316,7 @@
// Tokens and Reverse Polish Notation
-abstract class Token
+sealed abstract class Token
case class T(n: Int) extends Token
case object PL extends Token
case object TI extends Token