Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clojure & ClojureScript

Clojure & ClojureScript

A presentation at I.T.A.K.E. 2015

Stefan Kanev

May 28, 2015
Tweet

More Decks by Stefan Kanev

Other Decks in Programming

Transcript

  1. a * b + c * d (+ (* a

    b) (* c d))
  2. (defn classify [age] (if (<= 13 age 19) "Teenager" "A

    normal person")) (classify 18) ; "Teenager"
  3. (defn fib [n] (cond (= n 0) 1 (= n

    1) 1 :else (+ (fib (- n 1)) (fib (- n 2)))))
  4. (map (fn [n] (str "Mr. " n)) ["Anderson" "Bond" "Bean"])

    ; ("Mr. Anderson” ; "Mr. Bond" ; "Mr. Bean")
  5. (filter prime? (range 2 100)) ; (2 3 5 7

    11 13 17 19 23 29 31 37 41 ; 43 47 53 59 61 67 71 73 79 83 89 97)
  6. Y

  7. 1 2 3 a a ! (3 2 1) b

    ! (4 3 2 1) 4 b 5 c c ! (conj a 5)
  8. ref

  9. (def account (ref 100)) ; Thread 1 - Uncle Scrooge

    (dosync (alter account (fn [n] (* n 2))) (println "Scrooge: set to " @account)) ; Thread 2 - Donald Duck (dosync (alter account (fn [n] (+ n 50))) (println "Donald: set to " @account))
  10. Y

  11. PrintStream original = System.out; ByteArrayOutputStream output = new ByteArrayOutputStream(); try

    { PrintStream fileStream = new PrintStream(output); orgStream = System.out; System.setOut(fileStream); doStuff(); } finally { System.setOut(original); } String output = output.toString();
  12. (cond (= n 0) 1 (= n 1) 1 :else

    (+ (fib (- n 2)) (fib (- n 1)))) (if (= n 0) 1 (if (= n 1) 1 (+ (fib (- n 2)) (fib (- n 1)))))
  13. om