# HG changeset patch # User Christian Urban # Date 1606489430 0 # Node ID 90b267768329887db3bf80884af9addd2cce844a # Parent d29cd5883c7bc19beac2a14eb6c9be45ed2156d7 updated diff -r d29cd5883c7b -r 90b267768329 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 d29cd5883c7b -r 90b267768329 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 //================