| 51 |      1 | // Scala Lecture 1
 | 
|  |      2 | //=================
 | 
| 14 |      3 | 
 | 
| 26 |      4 | // Value assignments
 | 
| 123 |      5 | // (their names should be lower case)
 | 
| 199 |      6 | //====================================
 | 
| 21 |      7 | 
 | 
| 202 |      8 | 
 | 
| 14 |      9 | val x = 42
 | 
|  |     10 | val y = 3 + 4
 | 
| 123 |     11 | val z = x / y
 | 
|  |     12 | 
 | 
|  |     13 | // (you cannot reassign values: z = 9 will give an error)
 | 
| 14 |     14 | 
 | 
|  |     15 | 
 | 
| 125 |     16 | // Hello World
 | 
|  |     17 | //=============
 | 
|  |     18 | 
 | 
| 199 |     19 | // an example of a stand-alone Scala file
 | 
|  |     20 | // (in the assignments you must submit a plain Scala script)
 | 
| 125 |     21 | 
 | 
|  |     22 | object Hello extends App { 
 | 
|  |     23 |   println("hello world")
 | 
|  |     24 | }
 | 
|  |     25 | 
 | 
| 199 |     26 | // can then be called with
 | 
| 125 |     27 | //
 | 
|  |     28 | // $> scalac hello-world.scala
 | 
|  |     29 | // $> scala Hello
 | 
|  |     30 | //
 | 
|  |     31 | // $> java -cp /usr/local/src/scala/lib/scala-library.jar:. Hello
 | 
|  |     32 | 
 | 
|  |     33 | 
 | 
|  |     34 | 
 | 
| 25 |     35 | // Collections
 | 
|  |     36 | //=============
 | 
| 310 |     37 | 
 | 
| 14 |     38 | List(1,2,3,1)
 | 
|  |     39 | Set(1,2,3,1)
 | 
|  |     40 | 
 | 
| 268 |     41 | // ranges
 | 
| 14 |     42 | 1 to 10
 | 
|  |     43 | (1 to 10).toList
 | 
|  |     44 | 
 | 
|  |     45 | (1 until 10).toList
 | 
|  |     46 | 
 | 
| 268 |     47 | // picking an element in a list
 | 
| 33 |     48 | val lst = List(1, 2, 3, 1)
 | 
|  |     49 | lst(0)
 | 
|  |     50 | lst(2)
 | 
| 18 |     51 | 
 | 
| 34 |     52 | // some alterative syntax for lists
 | 
|  |     53 | 
 | 
| 189 |     54 | 1 :: 2 :: 3 :: Nil
 | 
| 23 |     55 | List(1, 2, 3) ::: List(4, 5, 6)
 | 
| 14 |     56 | 
 | 
| 308 |     57 | // also
 | 
|  |     58 | List(1, 2, 3) ++ List(4, 5, 6)
 | 
|  |     59 | 
 | 
|  |     60 | 
 | 
| 268 |     61 | // Equality in Scala is structural
 | 
|  |     62 | //=================================
 | 
| 199 |     63 | val a = "Dave"
 | 
|  |     64 | val b = "Dave"
 | 
|  |     65 | 
 | 
| 202 |     66 | if (a == b) println("Equal") else println("Unequal")
 | 
| 199 |     67 | 
 | 
|  |     68 | Set(1,2,3) == Set(3,1,2)
 | 
|  |     69 | List(1,2,3) == List(3,1,2)
 | 
|  |     70 | 
 | 
|  |     71 | 
 | 
| 308 |     72 | // this applies to "concrete" values...pretty much everything;
 | 
| 313 |     73 | // but for example you cannot compare functions (later),
 | 
|  |     74 | // and also not Arrays
 | 
|  |     75 | 
 | 
|  |     76 | Array(1) == Array(1)
 | 
| 199 |     77 | 
 | 
|  |     78 | 
 | 
| 25 |     79 | // Printing/Strings
 | 
|  |     80 | //==================
 | 
| 14 |     81 | 
 | 
|  |     82 | println("test")
 | 
| 15 |     83 | 
 | 
| 268 |     84 | val tst = "This is a " ++ "test" 
 | 
| 310 |     85 | 
 | 
| 313 |     86 | print(tst) 
 | 
|  |     87 | println(tst) 
 | 
| 14 |     88 | 
 | 
|  |     89 | val lst = List(1,2,3,1)
 | 
|  |     90 | 
 | 
| 202 |     91 | 
 | 
| 14 |     92 | println(lst.toString)
 | 
| 268 |     93 | 
 | 
|  |     94 | println(lst.mkString)
 | 
| 202 |     95 | println(lst.mkString(","))
 | 
| 14 |     96 | 
 | 
| 33 |     97 | println(lst.mkString(", "))
 | 
|  |     98 | 
 | 
| 14 |     99 | // some methods take more than one argument
 | 
| 202 |    100 | println(lst.mkString("{", ",", "}"))
 | 
| 14 |    101 | 
 | 
| 268 |    102 | // (in this case .mkString can take no, one, 
 | 
|  |    103 | // or three arguments...this has to do with
 | 
|  |    104 | // default arguments)
 | 
| 32 |    105 | 
 | 
| 200 |    106 | 
 | 
| 25 |    107 | // Conversion methods
 | 
|  |    108 | //====================
 | 
| 14 |    109 | 
 | 
|  |    110 | List(1,2,3,1).toString
 | 
|  |    111 | List(1,2,3,1).toSet
 | 
| 268 |    112 | 
 | 
| 310 |    113 | "hello".toList
 | 
| 202 |    114 | "hello".toList.tail
 | 
| 310 |    115 | 
 | 
|  |    116 | 
 | 
| 14 |    117 | 1.toDouble
 | 
|  |    118 | 
 | 
| 310 |    119 | 1L  // a long
 | 
|  |    120 | 1F  // a float
 | 
| 25 |    121 | 
 | 
| 32 |    122 | // useful list methods
 | 
|  |    123 | 
 | 
|  |    124 | List(1,2,3,4).length
 | 
| 25 |    125 | List(1,2,3,4).reverse
 | 
| 32 |    126 | List(1,2,3,4).max
 | 
|  |    127 | List(1,2,3,4).min
 | 
|  |    128 | List(1,2,3,4).sum
 | 
|  |    129 | List(1,2,3,4).take(2).sum
 | 
|  |    130 | List(1,2,3,4).drop(2).sum
 | 
| 199 |    131 | List(1,2,3,4,3).indexOf(3)
 | 
| 32 |    132 | 
 | 
| 36 |    133 | "1,2,3,4,5".split(",").mkString("\n")
 | 
| 202 |    134 | "1,2,3,4,5".split(",").toList
 | 
| 36 |    135 | "1,2,3,4,5".split(",3,").mkString("\n")
 | 
| 25 |    136 | 
 | 
| 200 |    137 | "abcdefg".startsWith("abc")
 | 
|  |    138 | 
 | 
|  |    139 | 
 | 
| 268 |    140 | // Types (see slide)
 | 
|  |    141 | //===================
 | 
| 25 |    142 | 
 | 
|  |    143 | /* Scala is a strongly typed language
 | 
|  |    144 |  
 | 
| 268 |    145 |  * base types
 | 
| 14 |    146 | 
 | 
| 25 |    147 |     Int, Long, BigInt, Float, Double
 | 
|  |    148 |     String, Char
 | 
| 268 |    149 |     Boolean...
 | 
| 25 |    150 | 
 | 
| 268 |    151 |  * compound types 
 | 
| 12 |    152 | 
 | 
| 268 |    153 |     List[Int]
 | 
| 25 |    154 |     Set[Double]
 | 
|  |    155 |     Pairs: (Int, String)        
 | 
|  |    156 |     List[(BigInt, String)]
 | 
| 200 |    157 |     Option[Int]
 | 
| 268 |    158 | 
 | 
|  |    159 |  * user-defined types (later)
 | 
|  |    160 | 
 | 
| 25 |    161 | */
 | 
| 12 |    162 | 
 | 
| 23 |    163 | 
 | 
| 268 |    164 | // you can make the type of a value explicit
 | 
| 247 |    165 | val name: String = "leo"
 | 
|  |    166 | 
 | 
| 14 |    167 | 
 | 
| 265 |    168 | // type errors
 | 
|  |    169 | math.sqrt("64")
 | 
|  |    170 | 
 | 
|  |    171 | // produces
 | 
|  |    172 | //
 | 
|  |    173 | // error: type mismatch;
 | 
|  |    174 | // found   : String("64")
 | 
|  |    175 | // required: Double
 | 
|  |    176 | // math.sqrt("64")
 | 
|  |    177 | 
 | 
| 268 |    178 | 
 | 
| 25 |    179 | // Pairs/Tuples
 | 
|  |    180 | //==============
 | 
| 14 |    181 | 
 | 
|  |    182 | val p = (1, "one")
 | 
|  |    183 | p._1
 | 
|  |    184 | p._2
 | 
|  |    185 | 
 | 
|  |    186 | val t = (4,1,2,3)
 | 
|  |    187 | t._4
 | 
|  |    188 | 
 | 
| 25 |    189 | 
 | 
| 200 |    190 | List(("one", 1), ("two", 2), ("three", 3))
 | 
|  |    191 | 
 | 
| 310 |    192 | 
 | 
| 25 |    193 | // Function Definitions
 | 
|  |    194 | //======================
 | 
| 14 |    195 | 
 | 
| 123 |    196 | def incr(x: Int) : Int = x + 1
 | 
|  |    197 | def double(x: Int) : Int = x + x
 | 
|  |    198 | def square(x: Int) : Int = x * x
 | 
| 14 |    199 | 
 | 
| 202 |    200 | def str(x: Int) : String = x.toString
 | 
| 268 |    201 | 
 | 
|  |    202 | incr(3)
 | 
|  |    203 | double(4)
 | 
| 25 |    204 | square(6)
 | 
| 268 |    205 | str(3)
 | 
| 21 |    206 | 
 | 
|  |    207 | 
 | 
| 36 |    208 | // The general scheme for a function: you have to give a type 
 | 
|  |    209 | // to each argument and a return type of the function
 | 
|  |    210 | //
 | 
|  |    211 | //  def fname(arg1: ty1, arg2: ty2,..., argn: tyn): rty = {
 | 
|  |    212 | //    body 
 | 
|  |    213 | //  }
 | 
|  |    214 | 
 | 
|  |    215 | 
 | 
| 200 |    216 | //
 | 
|  |    217 | // BTW: no returns!!
 | 
| 313 |    218 | // "last" line (expression) in a function determines the 
 | 
|  |    219 | // result
 | 
|  |    220 | 
 | 
| 200 |    221 | 
 | 
|  |    222 | def silly(n: Int) : Int = {
 | 
| 202 |    223 |   if (n < 10) n * n
 | 
|  |    224 |   else n + n
 | 
| 200 |    225 | }
 | 
|  |    226 | 
 | 
| 36 |    227 | 
 | 
| 123 |    228 | // If-Conditionals
 | 
|  |    229 | //=================
 | 
| 14 |    230 | 
 | 
| 200 |    231 | // - Scala does not have a then-keyword
 | 
| 310 |    232 | // - !!both if-else branches need to be present!!
 | 
| 189 |    233 | 
 | 
| 143 |    234 | def fact(n: Int) : Int = 
 | 
| 14 |    235 |   if (n == 0) 1 else n * fact(n - 1)
 | 
|  |    236 | 
 | 
| 36 |    237 | fact(5)
 | 
|  |    238 | fact(150)
 | 
|  |    239 | 
 | 
| 25 |    240 | /* boolean operators
 | 
|  |    241 |  
 | 
|  |    242 |    ==     equals
 | 
|  |    243 |    !      not
 | 
|  |    244 |    && ||  and, or
 | 
|  |    245 | */
 | 
| 15 |    246 | 
 | 
|  |    247 | 
 | 
| 189 |    248 | def fact2(n: BigInt) : BigInt = 
 | 
| 14 |    249 |   if (n == 0) 1 else n * fact2(n - 1)
 | 
|  |    250 | 
 | 
| 25 |    251 | fact2(150)
 | 
|  |    252 | 
 | 
| 26 |    253 | 
 | 
| 189 |    254 | def fib(n: Int) : Int =
 | 
| 14 |    255 |   if (n == 0) 1 else
 | 
| 26 |    256 |     if (n == 1) 1 else fib(n - 1) + fib(n - 2)
 | 
| 14 |    257 | 
 | 
|  |    258 | 
 | 
| 26 |    259 | //gcd - Euclid's algorithm
 | 
|  |    260 | 
 | 
| 202 |    261 | def gcd(a: Int, b: Int) : Int = {
 | 
|  |    262 |   if (b == 0) a 
 | 
| 272 |    263 |   else  gcd(b, a % b)
 | 
| 202 |    264 | }
 | 
| 26 |    265 | 
 | 
|  |    266 | gcd(48, 18)
 | 
|  |    267 | 
 | 
| 14 |    268 | 
 | 
| 123 |    269 | def power(x: Int, n: Int) : Int =
 | 
| 199 |    270 |   if (n == 0) 1 else x * power(x, n - 1) 
 | 
| 123 |    271 | 
 | 
|  |    272 | power(5, 5)
 | 
|  |    273 | 
 | 
|  |    274 | 
 | 
| 32 |    275 | 
 | 
| 26 |    276 | // For-Comprehensions (not For-Loops)
 | 
|  |    277 | //====================================
 | 
| 14 |    278 | 
 | 
| 202 |    279 | 
 | 
|  |    280 | for (n <- (1 to 10).toList) yield { 
 | 
|  |    281 |   square(n) + 1
 | 
|  |    282 | }
 | 
| 14 |    283 | 
 | 
| 25 |    284 | for (n <- (1 to 10).toList; 
 | 
|  |    285 |      m <- (1 to 10).toList) yield m * n
 | 
| 21 |    286 | 
 | 
|  |    287 | 
 | 
| 268 |    288 | // you can assign the result of a for-comprehension
 | 
|  |    289 | // to a value
 | 
| 26 |    290 | val mult_table = 
 | 
|  |    291 |   for (n <- (1 to 10).toList; 
 | 
|  |    292 |        m <- (1 to 10).toList) yield m * n
 | 
|  |    293 | 
 | 
| 202 |    294 | println(mult_table.mkString)
 | 
| 26 |    295 | mult_table.sliding(10,10).mkString("\n")
 | 
|  |    296 | 
 | 
| 200 |    297 | // the list/set/... can also be constructed in any 
 | 
|  |    298 | // other way
 | 
| 202 |    299 | for (n <- Set(10,12,4,5,7,8,10)) yield n * n
 | 
| 189 |    300 | 
 | 
| 25 |    301 | 
 | 
| 200 |    302 | // with if-predicates / filters
 | 
| 32 |    303 | 
 | 
|  |    304 | for (n <- (1 to 3).toList; 
 | 
|  |    305 |      m <- (1 to 3).toList;
 | 
| 202 |    306 |      if (n + m) % 2 == 0;
 | 
|  |    307 |      if (n * m) < 2) yield (n, m)
 | 
| 32 |    308 | 
 | 
| 148 |    309 | for (n <- (1 to 3).toList; 
 | 
|  |    310 |      m <- (1 to 3).toList;
 | 
| 202 |    311 |      if ((((n + m) % 2 == 0)))) yield (n, m)
 | 
| 32 |    312 | 
 | 
| 26 |    313 | // with patterns
 | 
|  |    314 | 
 | 
| 199 |    315 | val lst = List((1, 4), (2, 3), (3, 2), (4, 1))
 | 
| 26 |    316 | 
 | 
| 199 |    317 | for ((m, n) <- lst) yield m + n 
 | 
|  |    318 | 
 | 
|  |    319 | for (p <- lst) yield p._1 + p._2 
 | 
| 26 |    320 | 
 | 
| 25 |    321 | 
 | 
| 308 |    322 | // general pattern of for-yield 
 | 
|  |    323 | // (yield can be several lines)
 | 
| 189 |    324 | 
 | 
| 200 |    325 | for (p <- ...) yield {
 | 
| 189 |    326 |   // potentially complicated
 | 
|  |    327 |   // calculation of a result
 | 
|  |    328 | }
 | 
|  |    329 | 
 | 
| 200 |    330 | // Functions producing multiple outputs
 | 
|  |    331 | //======================================
 | 
| 189 |    332 | 
 | 
| 200 |    333 | def get_ascii(c: Char) : (Char, Int) = (c, c.toInt)
 | 
|  |    334 | 
 | 
|  |    335 | get_ascii('a')
 | 
|  |    336 | 
 | 
|  |    337 | 
 | 
|  |    338 | // .maxBy, sortBy with pairs
 | 
|  |    339 | def get_length(s: String) : (String, Int) = (s, s.length) 
 | 
|  |    340 | 
 | 
|  |    341 | val lst = List("zero", "one", "two", "three", "four", "ten")
 | 
|  |    342 | val strs = for (s <- lst) yield get_length(s)
 | 
|  |    343 | 
 | 
|  |    344 | strs.sortBy(_._2)
 | 
|  |    345 | strs.sortBy(_._1)
 | 
|  |    346 | 
 | 
|  |    347 | strs.maxBy(_._2)
 | 
|  |    348 | strs.maxBy(_._1)
 | 
|  |    349 | 
 | 
|  |    350 | 
 | 
|  |    351 | // For without yield
 | 
|  |    352 | //===================
 | 
| 25 |    353 | 
 | 
| 36 |    354 | // with only a side-effect (no list is produced),
 | 
| 32 |    355 | // has no "yield"
 | 
|  |    356 | 
 | 
|  |    357 | for (n <- (1 to 10)) println(n)
 | 
|  |    358 | 
 | 
|  |    359 | 
 | 
| 199 |    360 | // BTW: a roundabout way of printing out a list, say
 | 
|  |    361 | val lst = ('a' to 'm').toList
 | 
| 140 |    362 | 
 | 
| 308 |    363 | for (i <- (0 until lst.length)) println(lst(i))
 | 
| 202 |    364 | 
 | 
| 200 |    365 | // Why not just? Why making your life so complicated?
 | 
| 199 |    366 | for (c <- lst) println(c)
 | 
|  |    367 | 
 | 
| 310 |    368 | 
 | 
|  |    369 | 
 | 
| 199 |    370 | // Aside: concurrency 
 | 
| 308 |    371 | // scala -Yrepl-class-based -cp scala-parallel-collections_2.13-0.2.0.jar 
 | 
|  |    372 | 
 | 
| 32 |    373 | for (n <- (1 to 10)) println(n)
 | 
| 268 |    374 | 
 | 
|  |    375 | import scala.collection.parallel.CollectionConverters._
 | 
|  |    376 | 
 | 
| 32 |    377 | for (n <- (1 to 10).par) println(n)
 | 
|  |    378 | 
 | 
|  |    379 | 
 | 
| 36 |    380 | // for measuring time
 | 
| 140 |    381 | def time_needed[T](n: Int, code: => T) = {
 | 
| 32 |    382 |   val start = System.nanoTime()
 | 
| 140 |    383 |   for (i <- (0 to n)) code
 | 
| 32 |    384 |   val end = System.nanoTime()
 | 
| 140 |    385 |   (end - start) / 1.0e9
 | 
| 32 |    386 | }
 | 
|  |    387 | 
 | 
|  |    388 | val list = (1 to 1000000).toList
 | 
|  |    389 | time_needed(10, for (n <- list) yield n + 42)
 | 
|  |    390 | time_needed(10, for (n <- list.par) yield n + 42)
 | 
|  |    391 | 
 | 
| 308 |    392 | // ...but par does not make everything faster
 | 
|  |    393 | 
 | 
| 273 |    394 | list.sum
 | 
|  |    395 | list.par.sum
 | 
|  |    396 | 
 | 
|  |    397 | time_needed(10, list.sum)
 | 
|  |    398 | time_needed(10, list.par.sum)
 | 
| 32 |    399 | 
 | 
| 140 |    400 | 
 | 
| 308 |    401 | // Mutable vs Immutable
 | 
|  |    402 | //======================
 | 
| 200 |    403 | //
 | 
| 308 |    404 | // Remember:
 | 
| 200 |    405 | // - no vars, no ++i, no +=
 | 
|  |    406 | // - no mutable data-structures (no Arrays, no ListBuffers)
 | 
| 137 |    407 | 
 | 
| 308 |    408 | // But what the heck....
 | 
| 313 |    409 | // Q: Count how many elements are in the intersections of 
 | 
|  |    410 | //    two sets?
 | 
| 268 |    411 | // A; IMPROPER WAY (mutable counter)
 | 
| 200 |    412 | 
 | 
|  |    413 | def count_intersection(A: Set[Int], B: Set[Int]) : Int = {
 | 
|  |    414 |   var count = 0
 | 
| 308 |    415 |   for (x <- A.par; if (B contains x)) count += 1 
 | 
| 200 |    416 |   count
 | 
|  |    417 | }
 | 
| 32 |    418 | 
 | 
| 308 |    419 | val A = (0 to 999).toSet
 | 
|  |    420 | val B = (0 to 999 by 4).toSet
 | 
| 200 |    421 | 
 | 
|  |    422 | count_intersection(A, B)
 | 
|  |    423 | 
 | 
|  |    424 | // but do not try to add .par to the for-loop above
 | 
|  |    425 | 
 | 
| 32 |    426 | 
 | 
| 200 |    427 | //propper parallel version
 | 
|  |    428 | def count_intersection2(A: Set[Int], B: Set[Int]) : Int = 
 | 
|  |    429 |   A.par.count(x => B contains x)
 | 
|  |    430 | 
 | 
|  |    431 | count_intersection2(A, B)
 | 
|  |    432 | 
 | 
| 32 |    433 | 
 | 
| 308 |    434 | //another bad example
 | 
| 265 |    435 | def test() = {
 | 
|  |    436 |   var cnt = 0
 | 
|  |    437 |   for(i <- (1 to 1000000).par) cnt += 1
 | 
|  |    438 |   println(cnt)
 | 
|  |    439 | }
 | 
|  |    440 | 
 | 
|  |    441 | test()
 | 
|  |    442 | 
 | 
| 310 |    443 | // Option type
 | 
|  |    444 | //=============
 | 
|  |    445 | 
 | 
|  |    446 | //in Java if something unusually happens, you return null or something
 | 
|  |    447 | //
 | 
|  |    448 | //in Scala you use Options instead
 | 
|  |    449 | //   - if the value is present, you use Some(value)
 | 
|  |    450 | //   - if no value is present, you use None
 | 
|  |    451 | 
 | 
|  |    452 | 
 | 
|  |    453 | List(7,2,3,4,5,6).find(_ < 4)
 | 
|  |    454 | List(5,6,7,8,9).find(_ < 4)
 | 
|  |    455 | 
 | 
|  |    456 | 
 | 
|  |    457 | 
 | 
|  |    458 | // error handling with Options (no exceptions)
 | 
|  |    459 | //
 | 
|  |    460 | //  Try(something).getOrElse(what_to_do_in_case_of_an_exception)
 | 
|  |    461 | //
 | 
|  |    462 | import scala.util._
 | 
|  |    463 | import io.Source
 | 
|  |    464 | 
 | 
|  |    465 | val my_url = "https://nms.kcl.ac.uk/christian.urban/"
 | 
|  |    466 | 
 | 
|  |    467 | Source.fromURL(my_url).mkString
 | 
|  |    468 | 
 | 
|  |    469 | Try(Source.fromURL(my_url).mkString).getOrElse("")
 | 
|  |    470 | 
 | 
|  |    471 | Try(Some(Source.fromURL(my_url).mkString)).getOrElse(None)
 | 
|  |    472 | 
 | 
|  |    473 | 
 | 
|  |    474 | // the same for files
 | 
|  |    475 | Try(Some(Source.fromFile("text.txt").mkString)).getOrElse(None)
 | 
|  |    476 | 
 | 
|  |    477 | 
 | 
|  |    478 | 
 | 
|  |    479 | // how to implement a function for reading something from files...
 | 
|  |    480 | 
 | 
|  |    481 | def get_contents(name: String) : List[String] = 
 | 
|  |    482 |   Source.fromFile(name).getLines.toList
 | 
|  |    483 | 
 | 
|  |    484 | get_contents("test.txt")
 | 
|  |    485 | 
 | 
|  |    486 | // slightly better - return Nil
 | 
|  |    487 | def get_contents(name: String) : List[String] = 
 | 
|  |    488 |   Try(Source.fromFile(name).getLines.toList).getOrElse(List())
 | 
|  |    489 | 
 | 
|  |    490 | get_contents("text.txt")
 | 
|  |    491 | 
 | 
|  |    492 | // much better - you record in the type that things can go wrong 
 | 
|  |    493 | def get_contents(name: String) : Option[List[String]] = 
 | 
|  |    494 |   Try(Some(Source.fromFile(name).getLines.toList)).getOrElse(None)
 | 
|  |    495 | 
 | 
|  |    496 | get_contents("text.txt")
 | 
|  |    497 | get_contents("test.txt")
 | 
|  |    498 | 
 | 
|  |    499 | 
 | 
|  |    500 | 
 | 
| 32 |    501 | 
 | 
|  |    502 | // Further Information
 | 
|  |    503 | //=====================
 | 
|  |    504 | 
 | 
| 200 |    505 | // The Scala homepage and general information is at
 | 
| 32 |    506 | //
 | 
|  |    507 | //  http://www.scala-lang.org
 | 
| 123 |    508 | //	http://docs.scala-lang.org
 | 
|  |    509 | //
 | 
|  |    510 | //
 | 
|  |    511 | // It should be fairly easy to install the Scala binary and
 | 
| 200 |    512 | // run Scala on the commandline. People also use Scala with 
 | 
|  |    513 | // Vim and Jedit. I currently settled on VS Code
 | 
| 123 |    514 | //
 | 
| 200 |    515 | //   https://code.visualstudio.com
 | 
| 123 |    516 | //
 | 
| 200 |    517 | // There are also plugins for Eclipse and IntelliJ - YMMV.
 | 
|  |    518 | // Finally there are online editors specifically designed for 
 | 
|  |    519 | // running Scala applications (but do not blame me if you lose 
 | 
|  |    520 | // all what you typed in):
 | 
| 123 |    521 | //
 | 
| 200 |    522 | //   https://scalafiddle.io 
 | 
|  |    523 | //   https://scastie.scala-lang.org
 | 
| 124 |    524 | //
 | 
| 123 |    525 | //
 | 
|  |    526 | //
 | 
|  |    527 | // Scala Library Docs
 | 
| 124 |    528 | //====================
 | 
| 123 |    529 | //
 | 
|  |    530 | //  http://www.scala-lang.org/api/current/
 | 
|  |    531 | //
 | 
|  |    532 | // Scala Tutorials
 | 
|  |    533 | //
 | 
|  |    534 | //  http://docs.scala-lang.org/tutorials/
 | 
|  |    535 | //
 | 
|  |    536 | // There are also a massive number of Scala tutorials on youtube
 | 
| 200 |    537 | // and there are tons of books and free material. Google is your 
 | 
|  |    538 | // friend.
 | 
| 32 |    539 | 
 | 
|  |    540 | 
 | 
| 170 |    541 | 
 | 
|  |    542 | 
 | 
|  |    543 | 
 | 
|  |    544 | 
 | 
|  |    545 | 
 | 
|  |    546 | 
 | 
|  |    547 | 
 | 
| 195 |    548 | 
 | 
|  |    549 | 
 | 
|  |    550 | 
 | 
|  |    551 | 
 | 
|  |    552 | 
 | 
|  |    553 | 
 |