Slide 1

Slide 1 text

Reading Clojure Ricardo J. Méndez [email protected] @ArgesRic
 https://mastodon.social/@ricardojmendez

Slide 2

Slide 2 text

@ArgesRic This is about the thought process when evaluating things.

Slide 3

Slide 3 text

@ArgesRic “What in the name of Cthulhu’s green tentacles did I commit to?”

Slide 4

Slide 4 text

@ArgesRic Show of hands • Who here isn't programming in Clojure yet? • Who is kind of familiar with the language but still finding their footing? • Who considers themselves to be fully comfortable in it?

Slide 5

Slide 5 text

@ArgesRic This one’s for the first two.

Slide 6

Slide 6 text

@ArgesRic Learning stages • First we learn by reading; • Then we learn by imitating; • And finally, we learn by creating.

Slide 7

Slide 7 text

@ArgesRic I bollocksed up the first two.

Slide 8

Slide 8 text

@ArgesRic Clojure can be hard to read because of how simple it is.

Slide 9

Slide 9 text

@ArgesRic Syntax is that part of the language that’s set in stone.

Slide 10

Slide 10 text

@ArgesRic

Slide 11

Slide 11 text

@ArgesRic Let’s describe how we see this.

Slide 12

Slide 12 text

@ArgesRic

Slide 13

Slide 13 text

@ArgesRic

Slide 14

Slide 14 text

@ArgesRic Tokens are the wrong way of thinking about Clojure.

Slide 15

Slide 15 text

@ArgesRic

Slide 16

Slide 16 text

@ArgesRic So let’s dissect things a bit.

Slide 17

Slide 17 text

@ArgesRic (1 2 3) 
 [1 2 3]
 (+ 1 2 3)
 [+ 1 2 3]

Slide 18

Slide 18 text

@ArgesRic Evaluation semantics

Slide 19

Slide 19 text

@ArgesRic (+ 1 2 3) 
 (1 2 3)

Slide 20

Slide 20 text

@ArgesRic Trick question!

Slide 21

Slide 21 text

@ArgesRic (+ 1 2 3) 
 (1 2 3)

Slide 22

Slide 22 text

@ArgesRic We can always quote a list.

Slide 23

Slide 23 text

@ArgesRic If you’re joining us from Java… Or C#… 
 
 Or not-a-LISP...

Slide 24

Slide 24 text

@ArgesRic “Yeah, yeah, homoiconicity, we get it”

Slide 25

Slide 25 text

@ArgesRic *except all those special cases…

Slide 26

Slide 26 text

@ArgesRic (if odd? (do-something [1 3 5 7]) (do-another-thing [0 2 4 6]))

Slide 27

Slide 27 text

@ArgesRic (if odd? (do-something [1 3 5 7]) (do-another-thing [0 2 4 6]))

Slide 28

Slide 28 text

@ArgesRic (if odd? (do-something [1 3 5 7]) (do-another-thing [0 2 4 6]))

Slide 29

Slide 29 text

@ArgesRic A special form aside…

Slide 30

Slide 30 text

@ArgesRic “That’s the stuff that’s different!”

Slide 31

Slide 31 text

@ArgesRic They aren’t special cases. They are primitives.

Slide 32

Slide 32 text

@ArgesRic Primitives are so rare they are special.

Slide 33

Slide 33 text

@ArgesRic Back to the if

Slide 34

Slide 34 text

@ArgesRic (if odd? (do-something [1 3 5 7]) (do-another-thing [0 2 4 6]))

Slide 35

Slide 35 text

@ArgesRic (if odd? (do-something [1 3 5 7]) (do-another-thing [0 2 4 6]))

Slide 36

Slide 36 text

@ArgesRic (if odd? (do-something [1 3 5 7]) (do-another-thing [0 2 4 6]))

Slide 37

Slide 37 text

@ArgesRic (if odd? (do-something [1 3 5 7]) (do-another-thing [0 2 4 6]))

Slide 38

Slide 38 text

@ArgesRic “Branches, in parenthesis"

Slide 39

Slide 39 text

@ArgesRic (if got-a-list? (convert-to-string [1 3 5 7]) "Got something else")

Slide 40

Slide 40 text

@ArgesRic We are always evaluating. Stop thinking on terms of “execution”.

Slide 41

Slide 41 text

@ArgesRic Back to defn

Slide 42

Slide 42 text

@ArgesRic (defn plus-one [v w] (+ w v 1))

Slide 43

Slide 43 text

@ArgesRic ( defn ; We are evaluating this plus-one [v w] (+ w v 1) )

Slide 44

Slide 44 text

@ArgesRic ( defn plus-one ; All these [v w] ; are (+ w v 1) ; parameters. )

Slide 45

Slide 45 text

@ArgesRic ( defn plus-one ; This is an identifier [v w] (+ w v 1) )

Slide 46

Slide 46 text

@ArgesRic ( defn plus-one [v w] ; This is a vector w/param ids (+ w v 1) )

Slide 47

Slide 47 text

@ArgesRic ( defn plus-one [v w] (+ w v 1) ; This is a list to evaluate )

Slide 48

Slide 48 text

@ArgesRic ( defn ; We are invoking this plus-one ; This is an identifier [v w] ; This is a vector w/param ids (+ w v 1) ; This is a list to evaluate )

Slide 49

Slide 49 text

@ArgesRic (defn get-from-string [conn long-url] (let [url (db/get-url conn long-url) parsed (db/parse url)] (clean-up parsed)))

Slide 50

Slide 50 text

@ArgesRic ( defn get-from-string [conn long-url] ( let [url (db/get-url conn long-url) parsed (db/parse url)] (clean-up parsed) ) )

Slide 51

Slide 51 text

@ArgesRic ( defn get-from-string [conn long-url] ( let [url (db/get-url conn long-url) parsed (db/parse url)] (clean-up parsed) ) )

Slide 52

Slide 52 text

@ArgesRic ( defn get-from-string [conn long-url] ( let [url (db/get-url conn long-url) parsed (db/parse url)] (clean-up parsed) ) )

Slide 53

Slide 53 text

@ArgesRic ( defn get-from-string [conn long-url] ( let [url (db/get-url conn long-url) parsed (db/parse url)] (clean-up parsed) ) )

Slide 54

Slide 54 text

@ArgesRic Everything will follow this exact same pattern.

Slide 55

Slide 55 text

@ArgesRic The Tao of Clojure: There is nothing but the list.

Slide 56

Slide 56 text

@ArgesRic Let’s break some stuff!

Slide 57

Slide 57 text

@ArgesRic (inc) (inc 1) (inc inc)

Slide 58

Slide 58 text

@ArgesRic inc [inc] [inc 1] [inc 1 inc]

Slide 59

Slide 59 text

@ArgesRic (defn a-function [v] [+ 1 2 3 4 5] (plus-one 2 3) plus-one [inc] [inc 1] v)

Slide 60

Slide 60 text

@ArgesRic (defn a-function [v] [+ 1 2 3 4 5] (plus-one 2 3) plus-one [inc] [inc 1] v)

Slide 61

Slide 61 text

@ArgesRic Abusing the syntax to disabuse you of misconceptions.

Slide 62

Slide 62 text

@ArgesRic #1: "Everything needs to be wrapped in parenthesis." #2: "There’s all these special cases."

Slide 63

Slide 63 text

@ArgesRic (apply + [1 2 3 4])
 (get {+ 1 - 2 * 3} -)

Slide 64

Slide 64 text

@ArgesRic … we’re about out of time

Slide 65

Slide 65 text

@ArgesRic Thank you! Ricardo J. Méndez [email protected] @ArgesRic https://mastodon.social/@ricardojmendez https://numergent.com/talks/