Fertile Ground: The Roots of Clojure

7,963 views

Published on

Published in: Technology

Fertile Ground: The Roots of Clojure

  1. 1. Fertile Ground The Roots of Clojure
  2. 2. who
  3. 3. 1994
  4. 4. C++
  5. 5. C++'s strong typing has too many advantages to abandon...
  6. 6. C++'s strong typing has too many advantages to abandon... – Rich Hickey Callbacks in C++ Using Template Functors “ ”
  7. 7. Lisp!
  8. 8. ● Interfaces ● Sub-typing ● Polymorphism ● Encapsulation ● JVM ● Memory model
  9. 9. ● Implementation inheritance ● Hierarchies ● Kingdom of Nouns ● Mutability ● Imperative ● Very Verbose Verbosity
  10. 10. eschew
  11. 11. We managed to drag a lot of them about halfway to Lisp. – Guy L. Steele “ ”
  12. 12. C++ Lisp Java
  13. 13. zeitgeist
  14. 14. kingdom of nouns
  15. 15. Util doThis(...) doThat(...) doSomethingElse(...) toThis(...) toSomethingElse(...) toThat(...) fromThis(...) fromSomethingElse(...) fromThat(...) asThis(...) asSomethingElse(...) asThat(...) copy(...) equals(...) add(...) rem ove(...) update(...) com pareTo(...) eat(...) icate(...)
  16. 16. doThis(...) doThat(...) doSomethingElse(...) toThis(...) toSomethingElse(...) toThat(...) fromThis(...) fromSomethingElse(...) fromThat(...) asThis(...) asSomethingElse(...) asThat(...) copy(...) equals(...) add(...) remove(...) update(...) compareTo(...) eat(...) frobnicate(...) (ns utils)
  17. 17. String String cat(String that)
  18. 18. String String cat(String that)
  19. 19. String String cat(String that)
  20. 20. String String cat(String that)
  21. 21. StringWrapper String cat(String that) String
  22. 22. Concatenatable
  23. 23. Concatenatable cat(String this, that) String
  24. 24. Concatenatable cat(String this, that) String List cat(List this, that)
  25. 25. Concatenatable cat(String this, that) String List cat(List this, that) String[] cat(String[] this, that) Object[][] cat(Object[][] this, that)
  26. 26. subjectivity
  27. 27. (def rickey (ref {:in-love? false :likes [:hates-the-show, :funny, :lovely]}))
  28. 28. (def lucy (ref {:hates-the-show false, :funny true, :lovely true}))
  29. 29. (defn match? [m w] (reduce #(and % %2) ((apply juxt (:likes m)) w))) (defn court [m w] (if (match? m w) (assoc m :in-love? true) m))
  30. 30. (dosync (alter ricky court @lucy)) @rickey ;=> {:in-love? false :likes [:hates-the-show, :smart, :lovely]}
  31. 31. (dosync (ref-set lucy {:hates-the-show true, :smart true, :lovely true}))
  32. 32. (dosync (alter rickey court @lucy)) @rickey ;=> {:in-love? true :likes [:hates-the-show, :smart, :lovely]}
  33. 33. ?-
  34. 34. TDD
  35. 35. TDDTEST DRIVEN DENTISTRY
  36. 36. thoughtstuff
  37. 37. TDD
  38. 38. T__
  39. 39. take 2 [1,2,3,4,5] drop 2 [1,2,3,4,5] sum [1,2,3,4,5] product [1,2,3,4,5] cycle [1,2,3] repeat 9 iterate (1+) 0 takeWhile (<3) [1,2,3,4,5] dropWhile (<3) [1,2,3,4,5] splitAt 3 [1,2,3,4,5] any (<5) [1,2,3,4,5] all even [2,4,6,8] [x*2 | x <- [0..], x*2 < 9] zip [1,2,3] [10,11,12]
  40. 40. take 2 [1,2,3,4,5] drop 2 [1,2,3,4,5] sum [1,2,3,4,5] product [1,2,3,4,5] cycle [1,2,3] repeat 9 iterate (1+) 0 takeWhile (<3) [1,2,3,4,5] dropWhile (<3) [1,2,3,4,5] splitAt 3 [1,2,3,4,5] any (<5) [1,2,3,4,5] all even [2,4,6,8] [x*2 | x <- [0..], x*2 < 9] zip [1,2,3] [10,11,12] (take 2 [1,2,3,4,5]) (drop 2 [1,2,3,4,5]) (reduce + [1,2,3,4,5]) (reduce * [1,2,3,4,5]) (cycle [1,2,3]) (repeat 9) (iterate + 0) (take-while #(< 3) [1,2,3,4,5]) (drop-while #(< 3) [1,2,3,4,5]) (split-at 3 [1,2,3,4,5]) (some #(< 5) [1,2,3,4,5]) (every? even? [2,4,6,8]) (for [x (range) :let [y (* 2 x)] :while (< y 9)] y) (map vector [1,2,3] [10,11,12])
  41. 41. laziness
  42. 42. - explosion - non-termination - full-realization
  43. 43. - explosion - non-termination - full-realization
  44. 44. windowed
  45. 45. monetDB
  46. 46. - MVCC - Snapshot Isolation - Transactions
  47. 47. set! set! set! set! set! set! set! set! set! set! set! set! set! set! set! set!set! set! set! set! set!set!
  48. 48. set!
  49. 49. ml
  50. 50. set! val r = ref 5; !r; > val it = 5 : int r := !r + 4; !r; > val it = 9 : int (def r (ref 5)) @r ;=> 5 (dosync (alter r + 4)) @r ;=> 9
  51. 51. -module(counter). -export([init/0, get/1]). init() -> spawn(fun() -> loop(0) end). loop(Value) -> receive {get, From} -> From ! Value, loop(Value+1) end. get(C) -> C ! {get, self()}, receive X -> X end.
  52. 52. -module(counter). -export([init/0, get/1]). init() -> spawn(fun() -> loop(0) end). loop(Value) -> receive {get, From} -> From ! Value, loop(Value+1) end. get(C) -> C ! {get, self()}, receive X -> X end. Process B receive {get, From} -> From ! Value, loop(Value+1) end.
  53. 53. Process B receive {get, From} -> From ! Value, loop(Value+1) end. Process A c(counter). C = counter:init(). counter:get(C). %=> 0 counter:get(C). %=> 1 get
  54. 54. Thread A (def C (agent 0)) (send-off C inc) @C %=> 1 Thread B inc (apply inc @C)
  55. 55. EEK!?
  56. 56. Thanks To ● You ● Rich Hickey ● Relevance ● Chris Houser ● Manning Publishing ● The fam
  57. 57. Questions? (example questions below) ● Joel or Mike? ● Best zombie movies? ● Good writing music? ● Parallels between Ornette Coleman and Clojure?
  58. 58. :fred :ethel :ricky :lucy {:ricky "lucy", :fred "ethel"} (.toUpper “fred”) ["fred" "ethel" "lucy"] {:keys [fred ethel lucy]} {1 “ethel” 2 “fred”} (m :fred) #{fred ethel lucy} “Fred” “Ethel” “Lucy” “Ricky”

×