Fairy Tale     Clojure
Who am I?   - Consultant Gigasquid Software LLC   - Clojure and Ruby Enthusiast   - Mother of two young children   - Read ...
What about you?
Prologue
Rich HickeyCreator of Clojure
C/ C++
C/ C++LISP
HammockDrivenDevelopment
From Data Sorcery with Clojure
th● First Clojure Public Release Sept 29 2007● Clojure 1.0 – May 4th, 2009● Latest Version 1.2 - Aug 19th, 2010
What isClojure?
What isClojure?           Dynamic
Dynamic                 Is a Princess CrownPrincess Crown
Dynamic●Expressive●Concise     (Lets you focus in the problem)●   Interactive - REPL
What isClojure?        Dynamic       Functional
Functional Functions are “First Class” citizens Pure Functions – No Side Effects         CLUCK!
Functional Functions are “First Class” citizens Pure Functions – No Side Effects         CLUCK!      Side Effect
Cleaner Code withFunctional Style
Cleaner Code withFunctional Style Object Orientation is Overrated Born of simulation – now used for everything, even when ...
Mutable stateful objects are the new spaghetti code (Rich Hickey)
Mutable stateful objects are the new spaghetti code (Rich Hickey)   Hard to to understand, test → why we need mock   objec...
Real life – you need stateLimit, identify and dont scatter it about your code.
What isClojure?        Dynamic       Functional      Concurrent
Immutable Objects +Functional Style =Concurrency
Immutable Objects + Functional Style = Concurrency                   Moores Law Free Lunch is Over.....
Yeah.I feel that way about Clojure.
What isClojure?         Dynamic        Functional       Concurrent      Java Interop
Wrapper Free Access to Java   (.toUpperCase "fred")   -> "FRED"
Native to the JVM
Solves the New LanguageLibrary Problem
What isClojure?               Dynamic        s              Functional     ro   ac             Concurrent M            Jav...
Clojure is a LISP- Code as Data- Macros allow you to extend thelanguage- Macros are executed at compilerpre-process time r...
Once upon a time ...
Once upon a time ...    Interactive!    http://www.try-clojure.org/
The Kingdom of Clojureland was ruled bya very good king and queen. It was a veryspecial day. A baby had just been born!The...
user> (.getClass "Chloe")java.lang.Stringuser> (.toUpperCase "Chloe")"CHLOE"
She grew from a beautiful baby into acute toddler and said her first word.               user> (println "Mama")           ...
She just loved to make lists user=> ("mom" "dad" "milk" "juice") ("mom" "dad" "milk" "juice")        Look Mommy – No commas!
Vectors too. user=> [1 2 "Buckle my shoe"] [1 2 "Buckle my shoe"]        Look Mommy – No commas!
When she got older she started making   maps of all her favorite things user=> {:drink "juice", :book "Fox in Socks", :toy...
She learned how to make her first Varuser=> (def my-name "Chloe")#user/my-nameuser=> my-name"Chloe"
She got a time-out for her first lieuser=> (if true "in trouble" "not me")"in trouble"user=> (if false "in trouble" "not m...
When she was old enough she got sentto a boarding school for Princesses.She had a hard time fitting in with theother imper...
Her teachers gave her a hard time forbeing different      Alright Children …      lets count from 0 to 9        user=> (ra...
Her teacher tried to punish her by  having her write “I will not be lazy”  100 times – but it only made it worse  when she...
Her teachers gave her a hard time forbeing different       Now children lets practice our for for       loops... Take a li...
She made it through these hard timeswith the support and love of herwonderful parents. And finallygraduated school and ret...
Unfortunately, Tragedy Struck.
Her parents were killed by a freakscheduling accident of the RoyalParade and the Royal Teddy BearBerzerkers War Games.
The kingdoms evil wizard decided thatnow was the time to strike...
He would unleash his ultimatemonster – The infinite headed hydraMuha ha!user=> (def hydra (repeat "hydra-head"))#user/hydr...
The kingdoms Beserker Teddy Bears putup a valiant fight. But the finitetroops could not keep up. TheKingdom would be destr...
user=> (defn defeat-hydra [h]   (replace {"hydra-head" "flower"} h))#user/defeat-hydrauser=> (take 5 (defeat-hydra hydra))...
After a few rounds – The evil wizardknew he had been beaten and he and thehydra disappeared into the flowerscented mists. ...
And everyone had a nice cup of tea.           The End
Epilogue
Whos using Clojure?FlightCaster    (Clojure Rails) – Clojure for statistical learningBankSimple   (Jruby Clojure Scala)The...
Want to Learn More?TryClojurehttps://github.com/functional-koans/clojure-koansProgramming Clojure by Stuart HallowayIntere...
Rich Hickeys Ant Colony    Demonstration• World populated with food and ants• Ants find food, bring home, drop pheromones• ...
CreditsImages:http://www.flickr.com/photos/joeshlabotnik/2054165824/sizes/m/in/photostream/http://data-sorcery.org/2010/12...
Fairy tale-clojure
Fairy tale-clojure
Upcoming SlideShare
Loading in …5
×

Fairy tale-clojure

2,251 views

Published on

Clojure is a powerful, elegant, and dynamic programming language on the JVM. This presentation is an introduction to the language with code examples presented in a Fairy Tale format.

1 Comment
3 Likes
Statistics
Notes
  • Typo? ’... for for ... ’ on slide 48.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
2,251
On SlideShare
0
From Embeds
0
Number of Embeds
35
Actions
Shares
0
Downloads
29
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

Fairy tale-clojure

  1. 1. Fairy Tale Clojure
  2. 2. Who am I? - Consultant Gigasquid Software LLC - Clojure and Ruby Enthusiast - Mother of two young children - Read lots of Fairy Tales
  3. 3. What about you?
  4. 4. Prologue
  5. 5. Rich HickeyCreator of Clojure
  6. 6. C/ C++
  7. 7. C/ C++LISP
  8. 8. HammockDrivenDevelopment
  9. 9. From Data Sorcery with Clojure
  10. 10. th● First Clojure Public Release Sept 29 2007● Clojure 1.0 – May 4th, 2009● Latest Version 1.2 - Aug 19th, 2010
  11. 11. What isClojure?
  12. 12. What isClojure? Dynamic
  13. 13. Dynamic Is a Princess CrownPrincess Crown
  14. 14. Dynamic●Expressive●Concise (Lets you focus in the problem)● Interactive - REPL
  15. 15. What isClojure? Dynamic Functional
  16. 16. Functional Functions are “First Class” citizens Pure Functions – No Side Effects CLUCK!
  17. 17. Functional Functions are “First Class” citizens Pure Functions – No Side Effects CLUCK! Side Effect
  18. 18. Cleaner Code withFunctional Style
  19. 19. Cleaner Code withFunctional Style Object Orientation is Overrated Born of simulation – now used for everything, even when inappropriate - Rich Hickey
  20. 20. Mutable stateful objects are the new spaghetti code (Rich Hickey)
  21. 21. Mutable stateful objects are the new spaghetti code (Rich Hickey) Hard to to understand, test → why we need mock objects and all the unit tests Concurrency is a disaster
  22. 22. Real life – you need stateLimit, identify and dont scatter it about your code.
  23. 23. What isClojure? Dynamic Functional Concurrent
  24. 24. Immutable Objects +Functional Style =Concurrency
  25. 25. Immutable Objects + Functional Style = Concurrency Moores Law Free Lunch is Over.....
  26. 26. Yeah.I feel that way about Clojure.
  27. 27. What isClojure? Dynamic Functional Concurrent Java Interop
  28. 28. Wrapper Free Access to Java (.toUpperCase "fred") -> "FRED"
  29. 29. Native to the JVM
  30. 30. Solves the New LanguageLibrary Problem
  31. 31. What isClojure? Dynamic s Functional ro ac Concurrent M Java Interop
  32. 32. Clojure is a LISP- Code as Data- Macros allow you to extend thelanguage- Macros are executed at compilerpre-process time rather than run-time
  33. 33. Once upon a time ...
  34. 34. Once upon a time ... Interactive! http://www.try-clojure.org/
  35. 35. The Kingdom of Clojureland was ruled bya very good king and queen. It was a veryspecial day. A baby had just been born!The new princess! user> "Chloe" "Chloe"
  36. 36. user> (.getClass "Chloe")java.lang.Stringuser> (.toUpperCase "Chloe")"CHLOE"
  37. 37. She grew from a beautiful baby into acute toddler and said her first word. user> (println "Mama") Mama nil Aww how cute! Her first side effect!
  38. 38. She just loved to make lists user=> ("mom" "dad" "milk" "juice") ("mom" "dad" "milk" "juice") Look Mommy – No commas!
  39. 39. Vectors too. user=> [1 2 "Buckle my shoe"] [1 2 "Buckle my shoe"] Look Mommy – No commas!
  40. 40. When she got older she started making maps of all her favorite things user=> {:drink "juice", :book "Fox in Socks", :toy "Purple Bear"}{:drink "juice", :book "Fox in Socks", :toy "Purple Bear"}
  41. 41. She learned how to make her first Varuser=> (def my-name "Chloe")#user/my-nameuser=> my-name"Chloe"
  42. 42. She got a time-out for her first lieuser=> (if true "in trouble" "not me")"in trouble"user=> (if false "in trouble" "not me")"not me"user=> (if nil "in trouble" "not me")"not me"
  43. 43. When she was old enough she got sentto a boarding school for Princesses.She had a hard time fitting in with theother imperative princesses. They madefun of her lisp and said she lookedfunny with all those parens. Ha! Ha!((((((((((()))))))))))
  44. 44. Her teachers gave her a hard time forbeing different Alright Children … lets count from 0 to 9 user=> (range 10) (0 1 2 3 4 5 6 7 8 9)
  45. 45. Her teacher tried to punish her by having her write “I will not be lazy” 100 times – but it only made it worse when she did:(take 100 (repeat "I will not be lazy"))("I will not be lazy" "I will not be lazy" "I will not be lazy""I will not be lazy" "I will not be lazy" "I will not be lazy" "Iwill not be lazy" "I will not be lazy" "I will not be lazy" "Iwill not be lazy" "I will not be lazy" "I will not be lazy" "I
  46. 46. Her teachers gave her a hard time forbeing different Now children lets practice our for for loops... Take a list and add up all the values inside [1, 2, 3, 4]user=> (reduce + [1 2 3 4])10
  47. 47. She made it through these hard timeswith the support and love of herwonderful parents. And finallygraduated school and returned home. user=> (defn graduated? [age] (>= age 18)) #user/graduated? user=> (graduated? 18) true
  48. 48. Unfortunately, Tragedy Struck.
  49. 49. Her parents were killed by a freakscheduling accident of the RoyalParade and the Royal Teddy BearBerzerkers War Games.
  50. 50. The kingdoms evil wizard decided thatnow was the time to strike...
  51. 51. He would unleash his ultimatemonster – The infinite headed hydraMuha ha!user=> (def hydra (repeat "hydra-head"))#user/hydrauser=> (take 5 hydra)("hydra-head" "hydra-head" "hydra-head" "hydra-head" "hydra-head")
  52. 52. The kingdoms Beserker Teddy Bears putup a valiant fight. But the finitetroops could not keep up. TheKingdom would be destroyed.The princess had to do something...
  53. 53. user=> (defn defeat-hydra [h] (replace {"hydra-head" "flower"} h))#user/defeat-hydrauser=> (take 5 (defeat-hydra hydra))("flower" "flower" "flower" "flower" "flower")user=> (take 10 (defeat-hydra hydra))("flower" "flower" "flower" "flower" "flower" "flower""flower" "flower" "flower" "flower")
  54. 54. After a few rounds – The evil wizardknew he had been beaten and he and thehydra disappeared into the flowerscented mists. Curses Chloe! Youve won thisround.... but Ill be back!
  55. 55. And everyone had a nice cup of tea. The End
  56. 56. Epilogue
  57. 57. Whos using Clojure?FlightCaster (Clojure Rails) – Clojure for statistical learningBankSimple (Jruby Clojure Scala)TheDeadline Clojure (Compojure, Ajax)
  58. 58. Want to Learn More?TryClojurehttps://github.com/functional-koans/clojure-koansProgramming Clojure by Stuart HallowayInterested in hacking? Twitter @carinmeier Email cmeier@gigasquidsoftware.com
  59. 59. Rich Hickeys Ant Colony Demonstration• World populated with food and ants• Ants find food, bring home, drop pheromones• Sense pheromones, food, home• Ants act independently, on multiple real threads• Model pheromone evaporation• Animated GUI• < 250 lines of Clojure
  60. 60. CreditsImages:http://www.flickr.com/photos/joeshlabotnik/2054165824/sizes/m/in/photostream/http://data-sorcery.org/2010/12/29/hammock-driven-dev/http://www.flickr.com/photos/vikramvetrivel/3912452314/http://www.flickr.com/photos/gotosira/4699302559/http://www.flickr.com/photos/horiavarlan/4263957082/http://www.flickr.com/photos/bobjudge/3444731119/http://xkcd.com/208/http://www.flickr.com/photos/26010466@N07/4027386085/sizes/m/in/photostream/http://www.flickr.com/photos/friarsbalsam/4609212148/sizes/m/in/photostream/http://www.flickr.com/photos/calliope/159571301/sizes/m/in/photostream/http://www.flickr.com/photos/seadam/2747922613/

×