learn         in half an hour        http://jeffkit.info
Scalable language                   (actor)JVM   ,also .net        DSL
Scala
tiobe 2010/1
Scala!
twitter   scala
foursquare                       rogueA Lift/MongoDB Query DSLVenue where (_.mayor eqs 1234)      and (_.categories contai...
&Scala
Scala
Code Time
println (“hello Scala”)
1   package info.jeffkit    object HelloScala {    2 def main(args : Array[String]) : Unit = {   3    	   println("hello w...
techparty say helloDSL
package info.jeffkit1   class Group(val name:String){    	 def say(msg:String):Unit = {    	 	 println ("The Group " + thi...
hello
1class Group private (val name:String){	 def say(msg:String):Unit = {	 	 println ("The Group " + this.name + " say : " + m...
1def   play(game:String,members:Array[Member],perform:Member => Unit) = {	     	  println ("The group is playing a game : ...
//lambda	 1 techparty.play("introduce your self", members, member => println ("My name is " +member.name))		      //	2    ...
python fans   mixin
1       trait Fan{        	   def like() = "techparty"        }        trait JavaFan extends Fan{        	   override def ...
1def search(condition:Any):String = {	 2 condition match {   		 	 	 case "sleepy" =>	 	 	 	 println("you look sleepy,sleep...
val receiver = self	 1 actor {	    	    receiver ! techparty.search("jeff",2010)   2	     }		 3   val at = actor {	    	  ...
Thank you!
Scala jeff
Scala jeff
Scala jeff
Upcoming SlideShare
Loading in...5
×

Scala jeff

2,987

Published on

1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
2,987
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
65
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Scala jeff

  1. 1. learn in half an hour http://jeffkit.info
  2. 2. Scalable language (actor)JVM ,also .net DSL
  3. 3. Scala
  4. 4. tiobe 2010/1
  5. 5. Scala!
  6. 6. twitter scala
  7. 7. foursquare rogueA Lift/MongoDB Query DSLVenue where (_.mayor eqs 1234) and (_.categories contains “thai”) orderAsc (_.popularity) fetch (10)
  8. 8. &Scala
  9. 9. Scala
  10. 10. Code Time
  11. 11. println (“hello Scala”)
  12. 12. 1 package info.jeffkit object HelloScala { 2 def main(args : Array[String]) : Unit = { 3 println("hello world") 4 } } 1 2 object -> main 3 4
  13. 13. techparty say helloDSL
  14. 14. package info.jeffkit1 class Group(val name:String){ def say(msg:String):Unit = { println ("The Group " + this.name + " say : " + msg) } } object HelloScala { def main(args : Array[String]) : Unit = { println("hello scala") 2 val techparty = new Group("techparty") techparty.say("hello scala") 3 techparty say "im the magic of DSL" 4 } } 1 2 3 4 DSL
  15. 15. hello
  16. 16. 1class Group private (val name:String){ def say(msg:String):Unit = { println ("The Group " + this.name + " say : " + msg) }}object Group{ 2 private val groups = Map( 3 "techparty" -> new Group("techparty"), "barcamp" -> new Group("barcamp"), "openparty" -> new Group("openparty") ) def getGroup(name:String) = {4 if (groups.contains(name)) groups(name) else null }} 1 2 3 Map 4
  17. 17. 1def play(game:String,members:Array[Member],perform:Member => Unit) = { println ("The group is playing a game : " + game ) members.foreach{ member => perform(member) 3 } }class Member(val name:String,val topic:String){ def this(name:String){ this(name,null) 2 }}val members = Array( new Member("laiyonghao","male",true,"2010,My choices"), 4 new Member("jeff","male",true,"learn scala in haft an hour"), new Member("iceberg") ) 1 2 3 List foreach 4 List
  18. 18. //lambda 1 techparty.play("introduce your self", members, member => println ("My name is " +member.name)) // 2 def present(member:Member) = { if (member.topic != null) println (member.name + " is presenting.") } techparty.play("present", members, present) 3 // , val potluck = techparty.play("potluck", members, _:Member => Unit) potluck(_.name + " is eating") // ============ curry =============== 4 techparty.play_curry("dismiss", members){ member => member.name + " is leaving and going home" } 1 lambda 2 3 4 curry
  19. 19. python fans mixin
  20. 20. 1 trait Fan{ def like() = "techparty" } trait JavaFan extends Fan{ override def like() = "java " + super.like() } 2 trait PythonFan extends Fan{ override def like() = "python " + super.like() } 3 val member = new Member("jeff","learn scala in haft an hour") with JavaFan with PythonFan 4 member.like() 1 ,trait 2 trait class 3 mixin with) 4 mixin
  21. 21. 1def search(condition:Any):String = { 2 condition match { case "sleepy" => println("you look sleepy,sleep 1 second") Thread.sleep(1000) 3 case q:String => println("search by a keyword :" + q) case ("name",name:String) => println("search by name : " + name) case (year:Int,month:Int) => println("search by year " + year +" and " + month) 4 case _ => println("cant handle your search");return "fail" } "success" } 1 2 3 4
  22. 22. val receiver = self 1 actor { receiver ! techparty.search("jeff",2010) 2 } 3 val at = actor { receiver ! (self,techparty.search("sleepy")) } println("waiting for actor to finish") 4 for(i <- 1 to 2){ receive { 5 case (at,status:String) => println("hey,at is finish his job,and thestatus is: " + status) case "success" => println("search finish") case "fail" => println("search fail") } } 1 actor 2 3 actor 4 for 4 case
  23. 23. Thank you!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×