23. Internal DSL’s in Scala Menu.i("Home")/”home” / *>>loggedIn>>User.AddUserMenusAfter employee salary for 2.weeks minus deductions for{ gross => federalIncomeTax is (25. percent_of gross) stateIncomeTax is (5. percent_of gross) insurancePremiums are (500. in gross.currency) retirementFundContributions are (10. percent_of gross) }
24. object Lunar extendsBaysick{ def main(args:Array[String])={ 10 PRINT "Welcome to Baysick Lunar Lander v0.9" 20 LET ('dist:= 100) 30 LET ('v := 1) 40 LET ('fuel := 1000) 50 LET ('mass:=1000) 60 PRINT "Youaredriftingtowardsthemoon." 70 PRINT "You must decidehowmuchfueltoburn." 80 PRINT "Toaccelerateenter a positive number" 90 PRINT "Todecelerate a negative" 100 PRINT "Distance "% 'dist%"km, "%"Velocity "% 'v %"km/s, "%"Fuel "% 'fuel 110 INPUT 'burn 120 IF ABS('burn)<= 'fuel THEN 150 130 PRINT "Youdon'thavethatmuch fuel" 140 GOTO 100 150 LET ('v := 'v + 'burn* 10 /('fuel + 'mass)) 160 LET ('fuel := 'fuel - ABS('burn)) 170 LET ('dist:= 'dist- 'v) 180 IF 'dist> 0 THEN 100 190 PRINT "Youhave hit thesurface" 200 IF 'v < 3 THEN 240 210 PRINT "Hit surface too fast ("% 'v %")km/s" 220 PRINT "You Crashed!" 230 GOTO 250 240 PRINT "Welldone" 250 END RUN } }
36. Structural (Duck) Typing defdoIn(resource:{def open(): Unit;def close(): Unit }){ resource.open(); // do some useful stuff ... resource.close(); } val a =newScalaObject{ def open(){} def close(){} } val b =newScalaObject{ def open(){} // def close() {} } doIn(a) doIn(b)// compilation error
37. Multiple parameter lists defdoIn(code:()=> Unit) (resource:{def open(): Unit;def close(): Unit }){ resource.open(); code() resource.close(); } doIn(()=>{ // do some useful stuff ... })(a) defmyUsefulFunc(){ // lots of lots of wonderful code .. } doIn(myUsefulFunc)(a)
38. Implicit Parameters defdoIn(code:()=> Unit) (implicit resource:{def open(): Unit;def close(): Unit }){ resource.open(); code() resource.close(); } implicitval a =newScalaObject{ def open(){} def close(){} } doIn(()=>{ // do some useful stuff ... }) (a)
39. XML val person =<personname="ŁukaszKuczera"> <addressvoivodeship="Pomorskie"> <city>Gdańsk</city> </address> </person> valname = person quot;@name” valaddress = person quot;address" valcity = address quot;city” val_city = person "city"
40. val xml = <divclass="rsswidget"> <ul> <li><ahref="http://www.quotationspage.com/qotd.html"> Quotes of the Day</a></li> <li><ahref="http://www.quotationspage.com/quotes/C._P._Snow"> C. P. Snow</a></li> <li><ahref="http://www.quotationspage.com/quotes/ unknown">unknown</a></li> <li><ahref="http://www.quotationspage.com/quotes/Frederick_Locker- Lampson">Frederick Locker-Lampson</a></li> </ul> </div> (xml "@href").slice(1, 4).foreach(url=>{ val quote =Source.fromURL(new URL(url.text)).mkString println(quote) })
41. valxml = <divclass="rsswidget"> <ul><li> <ahref="http://www.quotationspage.com/qotd.html">Quotes of the Day</a></li> <li><ahref="http://www.quotationspage.com/quotes/C._P._Snow"> C. P. Snow</a></li> <li><ahref="http://www.quotationspage.com/quotes/unknown">unknown</a></li> <li><ahref="http://www.quotationspage.com/quotes/Frederick_Locker- Lampson">Frederick Locker-Lampson</a></li> </ul> </div> (xml "@href").slice(1, 4).foreach(url=>{ valcon =new URL(url.toString).openConnection val reader =newBufferedReader(newInputStreamReader(con.getInputStream,"ISO-8859-1")) var line =""; while(line !=null){ line =reader.readLine if(line !=null)println(line) } con.getInputStream.close })
45. If I where to choose language other than Java it would be Scala
46. „I can honestly say if someone had shown me the Programming in Scala book by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy”
47. „Scala, it must be stated, is the current heir apparent to the Java throne. No other language on the JVM seems as capable of being a "replacement for Java" as Scala, and the momentum behind Scala is now unquestionable”
48. Scala Features TypeInference Uniform Access Principle Closures Curying Higher Order Functions PatternMatching Actors Generics (covariance, higher order kinds) Native XML support Abstractcontrolstructures Implicitconversions and parameters Advanced for expressions Annotations Combinatorparsing Traits Ducktyping Null „safety” (Option Type)
49. Join me and together we will rule the galaxy !