diff -r 99dcfdf5aed8 -r f51e593903ac progs/lecture1.scala --- a/progs/lecture1.scala Thu Nov 17 20:05:36 2022 +0000 +++ b/progs/lecture1.scala Mon Nov 21 15:57:45 2022 +0000 @@ -1,7 +1,24 @@ // Scala Lecture 1 //================= +// - List, Sets, Strings, ... +// - Value assignments (val vs var) +// - How to define functions? (What is returned?) +// - If-Conditions +val tmp = 0 +val result = !(tmp == 0) +val result = if (tmp == 0) true else false + +// expressions (if (tmp == 0) true else false) +// - For-Comprehensions (guards, with/without yield) +// +// +// - Options +// - Higher-Order Functions (short-hand notation) +// - maps (behind for-comprehensions) +// - Pattern-Matching +// - String-Interpolations // Value assignments // (their names should be lower case) @@ -180,6 +197,7 @@ // you can make the type of a value explicit val name = "bob" +val name : String = "bob" // type errors math.sqrt("64".toDouble) @@ -327,8 +345,6 @@ // with if-predicates / filters -if (1 == 2) "a" else "b" - for (n <- (1 to 3).toList; m <- (1 to 3).toList; if (n + m) % 2 == 0) yield (n, m) @@ -453,7 +469,7 @@ def count_intersection(A: Set[Int], B: Set[Int]) : Int = { var count = 0 - for (x <- A; if (B contains x)) count += 1 + for (x <- A.par; if (B contains x)) count += 1 count }