Slide 1

Slide 1 text

(Clojure) @samflores

Slide 2

Slide 2 text

Lisp

Slide 3

Slide 3 text

Lots of InSignificant Parenthesis

Slide 4

Slide 4 text

LISt Processing

Slide 5

Slide 5 text

(1 2 3) *

Slide 6

Slide 6 text

Homoiconicidade

Slide 7

Slide 7 text

(+ 2 3) ; 5

Slide 8

Slide 8 text

(+ 2 4 6) ; 12

Slide 9

Slide 9 text

(doc +) clojure.core/+ ([] [x] [x y] [x y & more]) Returns the sum of nums. (+) returns 0. Does not auto-promote longs, will throw on overflow. See also: +'

Slide 10

Slide 10 text

Funcional

Slide 11

Slide 11 text

(odd? 2) ; false

Slide 12

Slide 12 text

(def par? (fn [n] (even? n))) (par? 2); true

Slide 13

Slide 13 text

(def par? even?) (par? 2); true

Slide 14

Slide 14 text

(defn greet [name] (str "Hello, " name)) (greet "John"); Hello, John

Slide 15

Slide 15 text

(map :name [{:name "John" :age 15} {:name "Mary" :age 10}])

Slide 16

Slide 16 text

(reduce + (range 10))

Slide 17

Slide 17 text

(apply + (repeat 30 8)) ; 240

Slide 18

Slide 18 text

(def dobra (partial * 2)) (dobra 5) ; 10

Slide 19

Slide 19 text

Simplicidade

Slide 20

Slide 20 text

def fn #() if do let quote ‘() var #’() loop recur throw try formas especiais

Slide 21

Slide 21 text

alias and BEGIN begin break case class def defined? do else elsif END end ensure for if in module next not or redo rescue retry return self super then undef unless until when while yield Ruby

Slide 22

Slide 22 text

assert break class const continue default do double else enum extends final finally float for goto if implements import instanceof int interface long native new package private protected public return short static strictfp super switch synchronized this throw throws transient try void volatile while Java

Slide 23

Slide 23 text

Pragmatismo

Slide 24

Slide 24 text

(def b 2r101010) (def n 1337N) (def m 3.14159M) (def r #"(\d+)") data types

Slide 25

Slide 25 text

(def l '(1 2 3)) (def v [1 2 3]) (def m {:a 1 :b 2}) (def s #{:x :y :z}) data types

Slide 26

Slide 26 text

JVM*

Slide 27

Slide 27 text

(def today (java.Util.Date.)) (.year today) ; today.year() (Integer/parseInt "10") Java interop

Slide 28

Slide 28 text

Imutabilidade*

Slide 29

Slide 29 text

(def l '(1)) (conj l 2) (prn l) ; (1)

Slide 30

Slide 30 text

& Concorrência Paralelismo

Slide 31

Slide 31 text

STM atoms agents delays futures promisses refs core.async …

Slide 32

Slide 32 text

(def l (atom [])) (swap! l conj 1) atoms

Slide 33

Slide 33 text

(def c (agent 0)) (send c inc) (send c dec) (await c) agents

Slide 34

Slide 34 text

(defn long-running-job [n] (Thread/sleep 3000) (+ n 10)) (pmap long-running-job (range 100)) pmap

Slide 35

Slide 35 text

(def ch (chan)) (go (print (

Slide 36

Slide 36 text

Environment

Slide 37

Slide 37 text

(defroute "/" [] (home-handler)) (defroute "/:user” [user] (profile-handler user)) compojure

Slide 38

Slide 38 text

:dependencies [[org.clojure/clojure "1.6.0"] [org.clojure/core.async "0.1.346.0-17112a-alpha"]] leiningen

Slide 39

Slide 39 text

$ lein deps $ lein ring server leiningen

Slide 40

Slide 40 text

(select user (with address) (fields :firstName :lastName :address.state) (where {:email "[email protected]"})) korma

Slide 41

Slide 41 text

ClojureScript core.typed datomic Clojars jetty http-kit …

Slide 42

Slide 42 text

Comunidade

Slide 43

Slide 43 text

clojure.org clojure-doc.org clojuredocs.org grimoire.arrdem.com #clojure FreeNode

Slide 44

Slide 44 text

(obrigado) @samflores