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

Por que clojure

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Por que clojure

Pontos observados da linguagem clojure

Avatar for Octavio Turra

Octavio Turra

September 14, 2016

Other Decks in Programming

Transcript

  1. Como surgiu? Criada por Rich Hickey https://clojure.org/ “Realm of Lisp”

    [Benevolent dictator] Concorrência Funcional Homoiconicidade 2009 : 1.0 / 2016 : 1.8 λ
  2. Por que eu usaria? Homoiconicidade se dá pelo fato de

    que os dialetos de Lisp respeitam uma estruturação homogênea. Lisp (operador ..operandos) //form (funcao parametro parametro) (+ 1 2) (map sum [1 2 3 4 5])
  3. Por que eu usaria? Anonymous functions Funcional (fn [arg] (println

    arg)) Nil Punning High order functions Closures (str nil) => “” (map #(* % %) [1 2 3 4 5]) (defn f [x] (fn [y] (+ x y))) Threading expressions (->> (range 10) (map inc)) Laziness (take 5 (positive-numbers))
  4. Por que eu usaria? Multimétodos Polimorfismo em Runtime (defmulti area

    :shape) (defmethod area :rectangle ==[{:keys [l w]}] (* l w)) (defmethod area :circle ==[{:keys [r]}] (* Math/PI r r)) (area {:shape :circle :r 10}) => 314.1592653589793 (area {:shape :rectangle :l 5 :w 10}) => 50 Protocolos (defprotocol Foo ====(bar [x y]) ====(baz [x] [x y])) (deftype Bar [data] Foo ====(bar [x y] (println x y)) ====(baz [x] (println x)) ====(baz [x y] (println x y))) (let [b (Bar. "some data")] ====(.bar b "param") ====(.baz b) ====(.baz b "baz with param"))
  5. Por que eu usaria? Macros (defmacro defprivate [name args &

    body] ==`(defn ~(symbol name) ~args =====(if (:user @session) =======(do ~@body) ======="please log in"))) (defprivate foo [greeting] ==(println greeting))