Binary file Admin/2022-feedback.pdf has changed
Binary file Admin/2023-feedback.pdf has changed
Binary file Admin/2024-feedback.pdf has changed
Binary file Admin/2025-feedback.pdf has changed
--- a/progs/cube.scala Thu Dec 11 13:23:30 2025 +0000
+++ b/progs/cube.scala Mon Dec 15 18:42:41 2025 +0000
@@ -26,13 +26,15 @@
}
-abstract class Colour
-case object White extends Colour
-case object Yellow extends Colour
-case object Orange extends Colour
-case object Red extends Colour
-case object Green extends Colour
-case object Blue extends Colour
+enum Colour {
+ case White
+ case Yellow
+ case Orange
+ case Red
+ case Green
+ case Blue
+}
+import Colour._
// Faces
// -------
@@ -102,7 +104,8 @@
Face(c.f1.c11, c.f1.c12, c.f6.c21, c.f6.c22))
-// simple bf-search without generating a solution, just true
+// simple bf-search without generating a
+// solution, just true in case there is a solution
def actions(c: Cube) : List[Cube] =
List(up(c), clock(c), right(c))
--- a/progs/lecture5.scala Thu Dec 11 13:23:30 2025 +0000
+++ b/progs/lecture5.scala Mon Dec 15 18:42:41 2025 +0000
@@ -1,7 +1,9 @@
// Scala Lecture 5
//=================
+// reading of URLs / files
// (Immutable) OOP
+// being lazy in Scala
import scala.util._ // Try,...
@@ -10,11 +12,9 @@
val my_url = "https://urbanchr.github.io/"
-
+Source.fromURL(my_url ++ "foo")(using "ISO-8859-1").mkString
-Source.fromURL(my_url)(using "ISO-8859-1").mkString
-
-Try(Source.fromURL(my_url)(using "ISO-8859-1").mkString).toOption
+Try(Source.fromURL(my_url)(using "ISO-8859-1").mkString.take(100)).toOption
Try(Source.fromURL(my_url)(using "ISO-8859-1").mkString).getOrElse("")
@@ -29,12 +29,18 @@
def get_contents(name: String) : List[String] =
Try(Source.fromURL(name)(using "ISO-8859-1").getLines().toList).getOrElse(Nil)
-get_contents(my_url)
+get_contents(my_url + "foo")
// Object Oriented Programming in Scala
// =====================================
+def map(xs: List[Int], f : Int => Int) : List[Int] = ???
+
+map(List(1,2,3,4), _ + 1)
+
+List(1,2,3,4).map(_ + 1)
+
abstract class Animal
case class Bird(name: String) extends Animal {
@@ -384,18 +390,18 @@
enuml(1, "a").size
enuml(2, "a").size
enuml(3, "a").size
-enuml(4, "a").size // out of heap space
+// enuml(4, "a").size // out of heap space after several minutes
-def enum(rs: LazyList[Rexp]) : LazyList[Rexp] =
- rs #::: enum( (for (r1 <- rs; r2 <- rs) yield ALT(r1, r2)) #:::
+def enm(rs: LazyList[Rexp]) : LazyList[Rexp] =
+ rs #::: enm( (for (r1 <- rs; r2 <- rs) yield ALT(r1, r2)) #:::
(for (r1 <- rs; r2 <- rs) yield SEQ(r1, r2)) #:::
(for (r1 <- rs) yield STAR(r1)) )
-enum(LazyList(ZERO, ONE, CHAR('a'), CHAR('b'))).take(200).force
-enum(LazyList(ZERO, ONE, CHAR('a'), CHAR('b'))).take(5_000_000).force // out of memory
-
+enm(LazyList(ZERO, ONE, CHAR('a'), CHAR('b'))).take(200).force
+enm(LazyList(ZERO, ONE, CHAR('a'), CHAR('b'))).take(5_000_000).force
+enm(LazyList(ZERO, ONE, CHAR('a'), CHAR('b'))).take(10_000_000).force // runs out of space
def depth(r: Rexp) : Int = r match {
case ZERO => 0
@@ -406,9 +412,12 @@
case STAR(r1) => depth(r1) + 1
}
+enm(LazyList(ZERO, ONE, CHAR('a'), CHAR('b'))).dropWhile(depth(_) < 3).take(5_000).force
+
+
val is =
- (enum(LazyList(ZERO, ONE, CHAR('a'), CHAR('b')))
+ (enm(LazyList(ZERO, ONE, CHAR('a'), CHAR('b')))
.dropWhile(depth(_) < 3)
.take(10).foreach(println))