Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Intro Clojure

317 views

Published on

Quick introduction to Clojure @ Programmers in Padua

Published in: Software
  • Be the first to comment

  • Be the first to like this

Intro Clojure

  1. 1. (intro "Clojure") Matteo Barbieri barbieri.matteo@gmail.com @matteobarbieri
  2. 2. ?
  3. 3. Clojure is a dinamically-typed functional language (LISP dialect) running as an hosted language on the JVM (and JS) with a focus on interactivity, immutability, no side effects, laziness and concurrency
  4. 4. ©2007 Rich Hickey
  5. 5. LISP dialect
  6. 6. lang=knparens
  7. 7. var people = [{name: "Matteo", age: 33}, {name: "Paolo", age: 25}, {name: "Luca", age: 55}]; people.filter(function isYoung(p) { return p.age < 34; }).map(function(p) { return p.age; }).reduce(function(a,b) { return a + b; },0);
  8. 8. 13
  9. 9. (def people [{:name "Matteo" :age 33} {:name "Paolo" :age 25} {:name "Luca" :age 55}]) (defn young? [p] (< (:age p) 34)) (apply + (map :age (filter young? people)))
  10. 10. 12
  11. 11. =12 =13
  12. 12. SIMPLE
  13. 13. SIMPLE MADE EASY https://www.infoq.com/presentations/Simple-Made-Easy
  14. 14. SIMPLE ≠ EASY
  15. 15. DIFFICULT → EASY
  16. 16. SIMPLE | COMPLEX
  17. 17. SIMPLE
  18. 18. if (x + y > 0) x else y
  19. 19. AST = Abstract Syntax Tree
  20. 20. if cond elsethen
  21. 21. if (x + y > 0) yx
  22. 22. if > yx x + y 0
  23. 23. if > yx + 0 x y
  24. 24. if > yx + 0 x y if (x + y > 0) x else y
  25. 25. if > yx + 0 x y
  26. 26. UNLESS ANYONE?
  27. 27. unless (x + y > 0) y else x
  28. 28. if > yx + 0 x y
  29. 29. unless > xy + 0 x y
  30. 30. if > yx + 0 x y
  31. 31. every tree is a list () first element is the root other elements are children recur
  32. 32. if > yx + 0 x y (if …)
  33. 33. if > yx + 0 x y (if (> …) x y)
  34. 34. if > yx + 0 x y (if (> (+ …) 0) x y)
  35. 35. if > yx + 0 x y (if (> (+ x y) 0) x y)
  36. 36. CODE AS DATA
  37. 37. HOMOICONICITY
  38. 38. immutability, no side effects, laziness, concurrency etc.
  39. 39. INTERACTIVITY
  40. 40. REPL Read Evaluate Print Loop
  41. 41. DEMO

×