Your SlideShare is downloading. ×
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Into Clojure
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Into Clojure

658

Published on

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
658
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • * Sponsing\n* Andre møte\n
  • \n
  • Først lisp i 1958 John McCarthy\nIkke objektorientert\nYtelse nesten som Java\n
  • \n
  • \n
  • \n
  • \n
  • #### Nå har dere sett all syntaksen ####\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • #### Skog av funksjoner som kan operere på disse datastrukturene ####\nLa oss se på noen som er litt spesielle.\n
  • #### Skog av funksjoner som kan operere på disse datastrukturene ####\nLa oss se på noen som er litt spesielle.\n
  • #### Skog av funksjoner som kan operere på disse datastrukturene ####\nLa oss se på noen som er litt spesielle.\n
  • #### Skog av funksjoner som kan operere på disse datastrukturene ####\nLa oss se på noen som er litt spesielle.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. 11.10.2011
    • 2. Agenda• Intro til Clojure - Alf Kristian Støyle• Inkrementell utvikling med Clojure, Emacs og SLIME - Stig Henriksen• Clojure STM - Ole Christian Rynning• Eratosthenes sil: et eventyr om optimalisering - Bodil Stokke
    • 3. Clojure• General purpose• Lisp (List Processing)• Funksjonelt• Kompilert• Dynamisk typet
    • 4. Literaler"String" ;=> String
    • 5. Literaler "String"(class "String") ;=> java.lang.String String
    • 6. Literaler(class "String" "String") ;=> String java.lang.String(class #"regex") ;=> java.util.regex.Pattern(class 123) ;=> java.lang.Integer(class 2147483648) ;=> java.lang.Long(class 123M) ;=> java.math.BigDecimal(class 123N) ;=> clojure.lang.BigInt(class true) ;=> java.lang.Boolean(class false) ;=> java.lang.Boolean(class 42/43) ;=> clojure.lang.Ratio(class c) ;=> java.lang.Character(class foo) ;=> clojure.lang.Symbol(class :bar) ;=> clojure.lang.Keyword(class nil) ;=> nil
    • 7. Collection literaler; List(3 2 1); Vector[1 2 3]; Set#{1 2 3}; Map{1 "one", 2 "two"‚ 3 "three"}
    • 8. Collection literaler; List(3 2 1) -> (list 3 2 1); Vector[1 2 3] -> (vector 1 2 3); Set#{1 2 3} -> (hash-set 1 2 3); Map{1 "one", 2 "two"‚ 3 "three"} -> (hash-map 1 "one", 2 "two", 3 "three")
    • 9. Dette er en liste(+ 1 2)
    • 10. Dette er en liste(+ 1 2) ;=> (+ 1 2)
    • 11. Dette er en form(+ 1 2)
    • 12. Dette er en form(+ 1 2);=> 3
    • 13. Dette er en form(+ 1 2);=> 3
    • 14. Dette er en form(+ 1 2);=> 3
    • 15. Dette er en form(+ 1 2);=> 3
    • 16. Prefiks notasjon(+ 1 2);=> 3
    • 17. Dette er en form(apply + (1 2)) ;=> 3
    • 18. Dette er en form(apply + (1 2)) ;=> 3
    • 19. Dette er en form(apply + (1 2)) ;=> 3
    • 20. Dette er en java.lang.String "(+ 1 2)" ;=> "(+ 1 2)"
    • 21. Dette er en java.lang.Stringsom kan konverteres til en form(read-string "(+ 1 2)") ;=> (+ 1 2)
    • 22. Dette er en java.lang.String som kan konverteres til en form som kan evalueres(eval (read-string "(+ 1 2)")) ;=> 3
    • 23. Read-compile-evaluate1. Tekst konverteres til forms2. Forms blir konvertert til bytekode av compiler3. Bytekode evalueres
    • 24. Funksjoner(fn [n] (* 2 n))
    • 25. Funksjoner (fn [n] (* 2 n));=> #<core$eval376$fn__377 user$eval376$fn__377@5c76458f>
    • 26. Funksjoner((fn [n] (* 2 n)) 4)
    • 27. Funksjoner((fn [n] (* 2 n)) 4) ;=> 8
    • 28. Funksjoner(fn [n] (* 2 n))#(* 2 %)
    • 29. Funksjoner(fn [n] (* 2 n))#(* 2 %)#(* 2 %1)
    • 30. Funksjoner & Vars(def times-two (fn [n] (* 2 n)));=> #user/times-two
    • 31. Funksjoner & Vars(def times-two (fn [n] (* 2 n)));=> #user/times-two(times-two 4);=> 8
    • 32. Funksjoner & Vars(def times-two (fn [n] (* 2 n)))(defn times-two [n] (* 2 n))
    • 33. Immutable og persistente datastrukturer(def my-list (3 2 1)); => (3 2 1)
    • 34. Immutable og persistente datastrukturer(def my-list (3 2 1)); => (3 2 1)
    • 35. Immutable og persistente datastrukturer(def my-list (3 2 1)); => (3 2 1)(def my-other-list (cons 4 my-list)); => (4 3 2 1)
    • 36. Immutable og persistente datastrukturer(def my-list (3 2 1)); => (3 2 1)(def my-other-list (cons 4 my-list)); => (4 3 2 1)
    • 37. Immutable collections; List(3 2 1); Vector[1 2 3]; Set#{1 2 3}; Map{1 "one", 2 "two"‚ 3 "three"}
    • 38. first(first (1 2 3))(first [1 2 3])(first #{1 2 3})(first {:one "one" :two "two"})
    • 39. first(first (1 2 3));=> 1(first [1 2 3]);=> 1(first #{1 2 3});=> 1(first {:one "one" :two "two"})
    • 40. first(first (1 2 3));=> 1(first [1 2 3]);=> 1(first #{1 2 3});=> 1(first {:one "one" :two "two"});=> [:one "one"]
    • 41. rest(rest (1 2 3))(rest [1 2 3])(rest #{1 2 3})(rest {:one "one" :two "two"})
    • 42. rest(rest (1 2 3));=> (2 3)(rest [1 2 3]);=> (2 3)(rest #{1 2 3});=> (2 3)(rest {:one "one" :two "two"})
    • 43. rest(rest (1 2 3));=> (2 3)(rest [1 2 3]);=> (2 3)(rest #{1 2 3});=> (2 3)(rest {:one "one" :two "two"});=> ([:two "two"])
    • 44. rest(rest ())(rest [])(rest #{})(rest {})
    • 45. rest(rest ());=> ()(rest []);=> ()(rest #{});=> ()(rest {});=> ()
    • 46. get(get (1 2 3) 0)(get [1 2 3] 0)(get #{3 2 1} 1)(get {:one 1 :two 2 :three 3} :one)
    • 47. get(get (1 2 3) 0)(get [1 2 3] 0);=> 1(get #{3 2 1} 1)(get {:one 1 :two 2 :three 3} :one)
    • 48. get(get (1 2 3) 0)(get [1 2 3] 0);=> 1(get #{3 2 1} 1);=> 1(get {:one 1 :two 2 :three 3} :one)
    • 49. get(get (1 2 3) 0)(get [1 2 3] 0);=> 1(get #{3 2 1} 1);=> 1(get {:one 1 :two 2 :three 3} :one);=> 1
    • 50. get(get (1 2 3) 0);=> nil(get [1 2 3] 0);=> 1(get #{3 2 1} 1);=> 1(get {:one 1 :two 2 :three 3} :one);=> 1
    • 51. get(get (1 2 3) 0 "yay");=> yay(get [1 2 3] -1 "yay");=> yay(get #{3 2 1} 0 "yay");=> yay(get {:one 1 :two 2 :three 3} :zero "yay");=> yay
    • 52. collections er((1 2 3) 0) funksjoner([1 2 3] 0)(#{3 2 1} 1)({:one 1 :two 2 :three 3} :one)
    • 53. collections er((1 2 3) 0) funksjoner([1 2 3] 0);=> 1(#{3 2 1} 1);=> 1({:one 1 :two 2 :three 3} :one);=> 1
    • 54. noen collections er funksjoner((1 2 3) 0);=> java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.IFn([1 2 3] 0);=> 1(#{3 2 1} 1);=> 1({:one 1 :two 2 :three 3} :one);=> 1
    • 55. contains?(contains? (10 11 12) 10)(contains? [10 11 12] 1)(contains? #{3 2 1} 1)(contains? {:one 1 :two 2 :three 3} :one)
    • 56. contains?(contains? (10 11 12) 10)(contains? [10 11 12] 1)(contains? #{3 2 1} 1);=> true(contains? {:one 1 :two 2 :three 3} :one)
    • 57. contains?(contains? (10 11 12) 10)(contains? [10 11 12] 1)(contains? #{3 2 1} 1);=> true(contains? {:one 1 :two 2 :three 3} :one);=> true
    • 58. contains?(contains? (10 11 12) 10);=> false(contains? [10 11 12] 1)(contains? #{3 2 1} 1);=> true(contains? {:one 1 :two 2 :three 3} :one);=> true
    • 59. contains?(contains? (10 11 12) 10);=> false(contains? [10 11 12] 1);=> true(contains? #{3 2 1} 1);=> true(contains? {:one 1 :two 2 :three 3} :one);=> true
    • 60. .contains(.contains (10 11 12) 10)(.contains [10 11 12] 1)(.contains #{3 2 1} 1)(.contains {:one 1 :two 2 :three 3} :one)
    • 61. .contains(.contains (10 11 12) 10);=> true(.contains [10 11 12] 1);=> false(.contains #{3 2 1} 1);=> true(.contains {:one 1 :two 2 :three 3} :one)
    • 62. .contains(.contains (10 11 12) 10);=> true(.contains [10 11 12] 1);=> false(.contains #{3 2 1} 1);=> true(.contains {:one 1 :two 2 :three 3} :one);=> java.lang.IllegalArgumentException: No matching methodfound: contains for class clojure.lang.PersistentArrayMap
    • 63. .contains(.contains (10 11 12) 10);=> true(.contains [10 11 12] 1);=> false(.contains #{3 2 1} 1);=> true(.containsKey {:one 1 :two 2 :three 3} :one);=> true
    • 64. Java interop(new java.util.ArrayList);=> #<ArrayList []>
    • 65. Java interop(new java.util.ArrayList);=> #<ArrayList []>(java.util.ArrayList.);=> #<ArrayList []>
    • 66. Java interop(System/currentTimeMillis);=> 1318164613423(.size (new java.util.ArrayList));=> 0(. (new java.util.ArrayList) size);=> 0
    • 67. Makroer(infix (1 + 2));=> 3
    • 68. Makroer(infix (1 + 2));=> 3(defmacro infix [form] (list (second form) (first form) (first (nnext form))));=> #user/infix
    • 69. Read-compile-evaluate1. Tekst konverteres til forms2. Forms blir konvertert til bytekode av compiler3. Dersom compiler finner en makro, ekspander makro og begynn på 1.4. Bytekode evalueres
    • 70. Makroer(infix (1 + 2));=> 3(defmacro infix [form] (list (second form) (first form) (first (nnext form))));=> #user/infix
    • 71. Makroer(infix (1 + 2));=> 3(defmacro infix [form] (list (second form) (first form) (first (nnext form))));=> #user/infix(macroexpand (infix (1 + 2)));=> (+ 1 2)
    • 72. Makroer(defmacro infix [form] (list (second form) (first form) (first (nnext form))));=> #user/infix(defmacro infix [form] `(~(second form) ~(first form) ~@(nnext form)));=> #user/infix
    • 73. Makroer• The two rules of the macro club Programming Clojure - Stuart Halloway 2009
    • 74. Makroer• The two rules of the macro club 1. Don’t write macros. Programming Clojure - Stuart Halloway 2009
    • 75. Makroer• The two rules of the macro club 1. Don’t write macros. 2. Only write macros if that is the only way to encapsulate a pattern. Programming Clojure - Stuart Halloway 2009
    • 76. Makroer• The two rules of the macro club 1. Don’t write macros. 2. Only write macros if that is the only way to encapsulate a pattern. 3. You can write any macro that makes life easier for your callers when compared with an equivalent function. Programming Clojure - Stuart Halloway 2009
    • 77. REPL demo“late collections/funksjoner”

    ×