# HG changeset patch # User Christian Urban # Date 1606489430 0 # Node ID 03e3fa0f401caa915feb443145b2d35074247ccb # Parent 0d29bc6ba63993394fbf11323da9a2864a53c79c updated diff -r 0d29bc6ba639 -r 03e3fa0f401c pre_marking1/mk --- a/pre_marking1/mk Fri Nov 27 00:55:24 2020 +0000 +++ b/pre_marking1/mk Fri Nov 27 15:03:50 2020 +0000 @@ -9,11 +9,11 @@ cd $sd echo $sd touch . - cp ../../../../marking1/collatz_test.sh . - cp ../../../../marking1/collatz_test1.scala . - cp ../../../../marking1/collatz_test2.scala . - cp ../../../../marking1/collatz_test3.scala . - ./collatz_test.sh output1 + cp ../../../../../pre_marking1/collatz_test.sh . + cp ../../../../../pre_marking1/collatz_test1.scala . + cp ../../../../../pre_marking1/collatz_test2.scala . + cp ../../../../../pre_marking1/collatz_test3.scala . + ./collatz_test.sh output rm collatz_test.sh rm collatz_test1.scala rm collatz_test2.scala diff -r 0d29bc6ba639 -r 03e3fa0f401c progs/lecture3.scala --- a/progs/lecture3.scala Fri Nov 27 00:55:24 2020 +0000 +++ b/progs/lecture3.scala Fri Nov 27 15:03:50 2020 +0000 @@ -193,8 +193,22 @@ parse_date("26.11.2019") +// guards in pattern-matching +def foo(xs: List[Int]) : String = xs match { + case Nil => s"this list is empty" + case x :: xs if x % 2 == 0 + => s"the first elemnt is even" + case x :: y :: rest if x == y + => s"this has two elemnts that are the same" + case hd :: tl => s"this list is standard $hd::$tl" +} +foo(Nil) +foo(List(1,2,3)) +foo(List(1,2)) +foo(List(1,1,2,3)) +foo(List(2,2,2,3)) // Tail recursion //================