updated
authorChristian Urban <urbanc@in.tum.de>
Wed, 09 Nov 2016 15:07:23 +0000
changeset 25 6253f4681451
parent 24 66b97f9a40f8
child 26 a7afc2540a88
updated
progs/lecture1.scala
slides/slides01.pdf
slides/slides01.tex
--- a/progs/lecture1.scala	Wed Nov 09 13:36:13 2016 +0000
+++ b/progs/lecture1.scala	Wed Nov 09 15:07:23 2016 +0000
@@ -1,16 +1,16 @@
 // Lecture 1
-//==========
+//===========
 
-//**Assignments (values)**
-//(variable names should be lower case)
-//=====================================
+// Assignments (values)
+// (variable names should be lower case)
+//======================================
 
 val x = 42
 val y = 3 + 4
 
 
-//**Collections**
-//===============
+// Collections
+//=============
 List(1,2,3,1)
 Set(1,2,3,1)
 
@@ -26,8 +26,8 @@
 1::2::3::Nil
 List(1, 2, 3) ::: List(4, 5, 6)
 
-//**Printing/Strings**
-//====================
+// Printing/Strings
+//==================
 
 println("test")
 
@@ -43,26 +43,39 @@
 // some methods take more than one argument
 println(lst.mkString("[", ",", "]"))
 
-//**Conversion methods**
-//======================
+// Conversion methods
+//====================
 
 List(1,2,3,1).toString
 List(1,2,3,1).toSet
 "hello".toList
 1.toDouble
 
-//**Types**
-//=========
+
+List(1,2,3,4).reverse
+
+// Types
+//=======
+
+/* Scala is a strongly typed language
+ 
+ * Base types
 
-// Int, Long, BigInt, Float, Double
-// String, Char
-// List[Int], Set[Double]
-// Pairs: (Int, String)        
-// List[(BigInt, String)]
+    Int, Long, BigInt, Float, Double
+    String, Char
+    Boolean
+
+ * Compound types 
 
+    List[Int],
+    Set[Double]
+    Pairs: (Int, String)        
+    List[(BigInt, String)]
+*/
 
-//**Smart Strings**
-//=================
+// Smart Strings
+//===============
+
 println(">\n<")
 println(""">\n<""")
 
@@ -81,8 +94,8 @@
 println(lyrics)
 
 
-//**Pairs/Tuples**
-//================
+// Pairs/Tuples
+//==============
 
 val p = (1, "one")
 p._1
@@ -91,27 +104,43 @@
 val t = (4,1,2,3)
 t._4
 
-//**Function Definitions**
-//========================
+// Hello World
+//=============
+
+// show an example of a stand-alone scala file
+// remind that in the course work you are asked a 
+// plain scala "work-sheet"
+
+
+
+// Function Definitions
+//======================
 
 def square(x: Int): Int = x * x
 
-
+square(6)
 
 
-//**Ifs control structures**
-//==========================
+// If control structure
+//======================
 
 def fact(n: Int): Int = 
   if (n == 0) 1 else n * fact(n - 1)
 
-
-
+/* boolean operators
+ 
+   ==     equals
+   !      not
+   && ||  and, or
+   
+*/
 
 
 def fact2(n: BigInt): BigInt = 
   if (n == 0) 1 else n * fact2(n - 1)
 
+fact2(150)
+
 def fib(n: Int): Int =
   if (n == 0) 1 else
     if (n == 1) 1 else fib(n - 1) + f(n - 2)
@@ -120,23 +149,27 @@
 //a recursive function
 def gcd(x: Int, y: Int): Int = 2 //??? 
 
-//**String Interpolations**
-//=========================
+// String Interpolations
+//=======================
 
 
-//**Assert/Testing**
-====================
+// Assert/Testing
+//================
 
-//**For-Maps (not For-Loops)**
-//============================
+// For-Maps (not For-Loops)
+//==========================
 
 for (n <- (1 to 10).toList) yield square(n)
 
-for (n <- (1 to 10).toList; m <- (1 to 10).toList) yield m * n
-
-val mtable = for (n <- (1 to 10).toList; m <- (1 to 10).toList) yield m * n
-
-mtable.sliding(10,10).toList.mkString(
+for (n <- (1 to 10).toList; 
+     m <- (1 to 10).toList) yield m * n
 
 
-// webpages
+val mtable = for (n <- (1 to 10).toList; 
+                  m <- (1 to 10).toList) yield m * n
+
+mtable.sliding(10,10).mkString("\n")
+
+
+// Webpages
+//==========
Binary file slides/slides01.pdf has changed
--- a/slides/slides01.tex	Wed Nov 09 13:36:13 2016 +0000
+++ b/slides/slides01.tex	Wed Nov 09 15:07:23 2016 +0000
@@ -100,7 +100,8 @@
     \textcolor{codegreen}{\texttt{Float}},
     \textcolor{codegreen}{\texttt{Double}}\\
     \textcolor{codegreen}{\texttt{String}},
-    \textcolor{codegreen}{\texttt{Char}}
+    \textcolor{codegreen}{\texttt{Char}}\\
+    \textcolor{codegreen}{\texttt{Boolean}}
   \end{tabular}
   \end{center}
 
@@ -114,7 +115,7 @@
     \textcolor{codegreen}{\texttt{List[(BigInt, String)]}} &
                                       lists of BigInt-String\\
                                       & pairs\\
-    \textcolor{codegreen}{\texttt{List[List[Int]]}} \\                                  
+    \textcolor{codegreen}{\texttt{List[List[Int]]}} & list of lists\\                                  
   \end{tabular}
   \end{center}