progs/lecture1.scala
changeset 265 59779ce322a6
parent 247 50a3b874008a
child 268 e43f7e92ba26
equal deleted inserted replaced
264:ecd989eee8bd 265:59779ce322a6
   141 
   141 
   142 
   142 
   143 val name: String = "leo"
   143 val name: String = "leo"
   144 
   144 
   145 
   145 
       
   146 // type errors
       
   147 math.sqrt("64")
       
   148 
       
   149 // produces
       
   150 //
       
   151 // error: type mismatch;
       
   152 // found   : String("64")
       
   153 // required: Double
       
   154 // math.sqrt("64")
       
   155 
   146 // Pairs/Tuples
   156 // Pairs/Tuples
   147 //==============
   157 //==============
   148 
   158 
   149 val p = (1, "one")
   159 val p = (1, "one")
   150 p._1
   160 p._1
   466   A.par.count(x => B contains x)
   476   A.par.count(x => B contains x)
   467 
   477 
   468 count_intersection2(A, B)
   478 count_intersection2(A, B)
   469 
   479 
   470 
   480 
       
   481 //another example
       
   482 def test() = {
       
   483   var cnt = 0
       
   484   for(i <- (1 to 1000000).par) cnt += 1
       
   485   println(cnt)
       
   486 }
       
   487 
       
   488 test()
       
   489 
   471 //for measuring time
   490 //for measuring time
   472 def time_needed[T](n: Int, code: => T) = {
   491 def time_needed[T](n: Int, code: => T) = {
   473   val start = System.nanoTime()
   492   val start = System.nanoTime()
   474   for (i <- (0 to n)) code
   493   for (i <- (0 to n)) code
   475   val end = System.nanoTime()
   494   val end = System.nanoTime()