progs/comb1.scala
changeset 467 b5ec11e89768
parent 462 fb5e1ef58049
child 470 8df654e9eb4e
equal deleted inserted replaced
466:9ec26df6d289 467:b5ec11e89768
   154 (One ~ One).parse("111")
   154 (One ~ One).parse("111")
   155 (One ~ One ~ One).parse("111")
   155 (One ~ One ~ One).parse("111")
   156 (One ~ One ~ One ~ One).parse("1111")
   156 (One ~ One ~ One ~ One).parse("1111")
   157 
   157 
   158 (One || Two).parse("111")
   158 (One || Two).parse("111")
       
   159 
       
   160 
       
   161 for (x <- List(1, 2, 3, 4)) println(x)
       
   162 for (x <- List(1, 2, 3, 4); if (2 < x)) yield (x.toString + x.toString)
       
   163 for (x <- List("2", "1", "3", "4", "1")) yield (x + x + x)
       
   164 
       
   165 (1, "one", '1')._3
       
   166 for ((x, y) <- List((1, "one"), (2, "two"), (3, "three"), (4,"many")); if (y == "many"))
       
   167   yield (x.toString + y)
       
   168 
       
   169 
       
   170 def square(n: Int) = {
       
   171   n * n
       
   172 }
       
   173 
       
   174 square(4 + 3 + 5)
       
   175 
       
   176 def bar(): Int = {
       
   177   bar()
       
   178   3
       
   179 }
       
   180 
       
   181 
       
   182 def foo(n: => Int) = {
       
   183   print("finished")
       
   184 }
       
   185 
       
   186 foo(bar())
       
   187 
       
   188 square(12) + square(10)
       
   189 
       
   190 
       
   191 def time_needed[T](i: Int, code: => T) = {
       
   192   val start = System.nanoTime()
       
   193   for (j <- 1 to i) code
       
   194   val end = System.nanoTime()
       
   195   (end - start)/(i * 1.0e9)
       
   196 }