progs/lecture1.scala
changeset 124 c45d3cd9a749
parent 123 556cd74cbba9
child 125 dcaab8068baa
equal deleted inserted replaced
123:556cd74cbba9 124:c45d3cd9a749
   224 }
   224 }
   225 
   225 
   226 gcd_db(48, 18)
   226 gcd_db(48, 18)
   227 
   227 
   228 
   228 
   229 // Assert/Testing
   229 // Asserts/Testing
   230 //================
   230 //================
   231 
   231 
   232 assert(gcd(48, 18) == 6)
   232 assert(gcd(48, 18) == 6)
   233 
   233 
   234 assert(gcd(48, 18) == 5, "The gcd test failed")
   234 assert(gcd(48, 18) == 5, "The gcd test failed")
   300 val url = """https://nms.kcl.ac.uk/christian.urban/""" 
   300 val url = """https://nms.kcl.ac.uk/christian.urban/""" 
   301 Source.fromURL(url)("ISO-8859-1").mkString
   301 Source.fromURL(url)("ISO-8859-1").mkString
   302 
   302 
   303 
   303 
   304 // function for looking up stockmarket data 
   304 // function for looking up stockmarket data 
   305 def price_lookup(symbol: String): String = {
   305 def price_lookup(symbol: String) : String = {
   306   val url = "https://download.finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=snl1"
   306   val url = "https://download.finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=snl1"
   307   Source.fromURL(url).mkString.drop(1).dropRight(2)
   307   Source.fromURL(url).mkString.drop(1).dropRight(2)
   308 }
   308 }
   309 
   309 
   310 price_lookup("GOOG")
   310 price_lookup("GOOG")
   371 //
   371 //
   372 // It should be fairly easy to install the Scala binary and
   372 // It should be fairly easy to install the Scala binary and
   373 // run Scala on the commandline. There are also at least 
   373 // run Scala on the commandline. There are also at least 
   374 // four IDEs you can use with Scala:
   374 // four IDEs you can use with Scala:
   375 //
   375 //
   376 //  (0) Some general information for setting up IDEs
   376 //  (0) Some general information about setting up IDEs
   377 //	    with Scala support can be found at
   377 //	    with Scala support can be found at
   378 //
   378 //
   379 //         http://docs.scala-lang.org/getting-started.html 
   379 //         http://docs.scala-lang.org/getting-started.html 
       
   380 //
   380 //
   381 //
   381 //  (1) Eclipse for Scala (one big bundle)
   382 //  (1) Eclipse for Scala (one big bundle)
   382 //
   383 //
   383 //         http://scala-ide.org/download/sdk.html
   384 //         http://scala-ide.org/download/sdk.html
   384 //  
   385 //  
   386 //
   387 //
   387 //         https://www.jetbrains.com/idea/
   388 //         https://www.jetbrains.com/idea/
   388 //		   http://docs.scala-lang.org/getting-started-intellij-track/getting-started-with-scala-in-intellij.html	  
   389 //		   http://docs.scala-lang.org/getting-started-intellij-track/getting-started-with-scala-in-intellij.html	  
   389 //
   390 //
   390 //  (3) Sublime (not free, but unlimited trial period; 
   391 //  (3) Sublime (not free, but unlimited trial period; 
   391 //	    needs SublimeREPL plugin)
   392 //	    needs Scala and SublimeREPL plugin)
   392 //
   393 //
   393 //         https://www.sublimetext.com
   394 //         https://www.sublimetext.com
   394 //
   395 //
   395 //  (4) Emacs (old-fashioned, but reliable)
   396 //  (4) Emacs (old-fashioned, but reliable)
   396 //
   397 //
   404 //
   405 //
   405 //         http://ensime.org/editors/emacs/scala-mode/   
   406 //         http://ensime.org/editors/emacs/scala-mode/   
   406 //   
   407 //   
   407 // There is also Scala support in the Atom editor, but my
   408 // There is also Scala support in the Atom editor, but my
   408 // experience is mixed. People also use Scala with Vim and Jedit.
   409 // experience is mixed. People also use Scala with Vim and Jedit.
       
   410 // Finally there is an online editor specifically designed for 
       
   411 // running Scala applications (but do not blame mne if you lose all 
       
   412 // what you typed in):
       
   413 //
       
   414 //      https://scalafiddle.io 
       
   415 //
       
   416 //
   409 //
   417 //
   410 // All of the IDEs above support a REPL for Scala. Some of them have
   418 // All of the IDEs above support a REPL for Scala. Some of them have
   411 // the very nifty feature of a Scala Worksheet -- you just save your
   419 // the very nifty feature of a Scala Worksheet -- you just save your
   412 // file and it will be automatically evaluated and the result pasted
   420 // file and it will be automatically evaluated and the result pasted
   413 // into your file. However, this way of writing Scala code never worked
   421 // into your file. However, this way of writing Scala code never worked
   414 // for me. I just use the REPL.
   422 // for me. I just use the REPL.
   415 //
   423 //
   416 //
   424 //
   417 // Scala Library Docs
   425 // Scala Library Docs
       
   426 //====================
   418 //
   427 //
   419 //  http://www.scala-lang.org/api/current/
   428 //  http://www.scala-lang.org/api/current/
   420 //
   429 //
   421 // Scala Tutorials
   430 // Scala Tutorials
   422 //
   431 //