75
Fertile Ground The Roots of Clojure

Fertile Ground: The Roots of Clojure

Embed Size (px)

Citation preview

Page 1: Fertile Ground: The Roots of Clojure

Fertile GroundThe Roots of Clojure

Page 2: Fertile Ground: The Roots of Clojure
Page 3: Fertile Ground: The Roots of Clojure

who

Page 4: Fertile Ground: The Roots of Clojure
Page 5: Fertile Ground: The Roots of Clojure

1994

Page 6: Fertile Ground: The Roots of Clojure

C++

Page 7: Fertile Ground: The Roots of Clojure

C++'s strong typing has too many advantages to abandon...

Page 8: Fertile Ground: The Roots of Clojure

C++'s strong typing has too many advantages to abandon...– Rich Hickey

Callbacks in C++ Using Template Functors

“ ”

Page 9: Fertile Ground: The Roots of Clojure
Page 10: Fertile Ground: The Roots of Clojure
Page 11: Fertile Ground: The Roots of Clojure
Page 12: Fertile Ground: The Roots of Clojure
Page 13: Fertile Ground: The Roots of Clojure

Lisp!

Page 14: Fertile Ground: The Roots of Clojure
Page 15: Fertile Ground: The Roots of Clojure
Page 16: Fertile Ground: The Roots of Clojure

● Interfaces● Sub-typing● Polymorphism● Encapsulation● JVM● Memory model

Page 17: Fertile Ground: The Roots of Clojure

● Implementation inheritance

● Hierarchies● Kingdom of Nouns● Mutability● Imperative● Very Verbose Verbosity

Page 18: Fertile Ground: The Roots of Clojure

eschew

Page 19: Fertile Ground: The Roots of Clojure

We managed to drag a lot of them about halfway to Lisp.– Guy L. Steele

“ ”

Page 20: Fertile Ground: The Roots of Clojure

C++ LispJava

Page 21: Fertile Ground: The Roots of Clojure
Page 22: Fertile Ground: The Roots of Clojure

zeitgeist

Page 23: Fertile Ground: The Roots of Clojure
Page 24: Fertile Ground: The Roots of Clojure

kingdom of nouns

Page 25: Fertile Ground: The Roots of Clojure

UtildoThis(...)doThat(...)doSomethingElse(...)toThis(...)

toSomethingElse(...)toThat(...)

fromThis(...)

fromSomethingElse(...)fromThat(...)

asThis(...)

asSomethingElse(...)asThat(...)

copy(...)equals(...)add(...)

rem

ove(

...)

upda

te(..

.)

com

pare

To(..

.)

eat(.

..)

frob

nica

te(.

..)

Page 26: Fertile Ground: The Roots of Clojure
Page 27: Fertile Ground: The Roots of Clojure

doThis(...)doThat(...)doSomethingElse(...)toThis(...)

toSomethingElse(...)toThat(...)

fromThis(...)

fromSomethingElse(...)fromThat(...)

asThis(...)

asSomethingElse(...)asThat(...)

copy(...)equals(...)add(...)

remove(...)

update(...)compareTo(...)

eat(...)frobnicate(...)

(ns utils)

Page 28: Fertile Ground: The Roots of Clojure

String

String cat(String that)

Page 29: Fertile Ground: The Roots of Clojure

String

String cat(String that)

Page 30: Fertile Ground: The Roots of Clojure

String

String cat(String that)

Page 31: Fertile Ground: The Roots of Clojure

String

String cat(String that)

Page 32: Fertile Ground: The Roots of Clojure

StringWrapper

String cat(String that)

String

Page 33: Fertile Ground: The Roots of Clojure

Concatenatable

Page 34: Fertile Ground: The Roots of Clojure

Concatenatable

cat(String this, that)String

Page 35: Fertile Ground: The Roots of Clojure

Concatenatable

cat(String this, that)String List

cat(List this, that)

Page 36: Fertile Ground: The Roots of Clojure

Concatenatable

cat(String this, that)String List

cat(List this, that)

String[]

cat(String[] this, that)

Object[][]

cat(Object[][] this, that)

Page 37: Fertile Ground: The Roots of Clojure
Page 38: Fertile Ground: The Roots of Clojure

subjectivity

Page 39: Fertile Ground: The Roots of Clojure

(def rickey (ref {:in-love? false :likes [:hates-the-show, :funny, :lovely]}))

Page 40: Fertile Ground: The Roots of Clojure

(def lucy (ref {:hates-the-show false, :funny true, :lovely true}))

Page 41: Fertile Ground: The Roots of Clojure

(defn match? [m w] (reduce #(and % %2) ((apply juxt (:likes m)) w)))

(defn court [m w] (if (match? m w) (assoc m :in-love? true) m))

Page 42: Fertile Ground: The Roots of Clojure

(dosync (alter ricky court @lucy))

@rickey

;=> {:in-love? false :likes [:hates-the-show, :smart, :lovely]}

Page 43: Fertile Ground: The Roots of Clojure

(dosync (ref-set lucy {:hates-the-show true, :smart true, :lovely true}))

Page 44: Fertile Ground: The Roots of Clojure

(dosync (alter rickey court @lucy))

@rickey

;=> {:in-love? true :likes [:hates-the-show, :smart, :lovely]}

Page 45: Fertile Ground: The Roots of Clojure

?-

Page 46: Fertile Ground: The Roots of Clojure

TDD

Page 47: Fertile Ground: The Roots of Clojure

TDDTEST DRIVEN DENTISTRY

Page 48: Fertile Ground: The Roots of Clojure

thoughtstuff

Page 49: Fertile Ground: The Roots of Clojure

TDD

Page 50: Fertile Ground: The Roots of Clojure

T__

Page 51: Fertile Ground: The Roots of Clojure
Page 52: Fertile Ground: The Roots of Clojure

take 2 [1,2,3,4,5]drop 2 [1,2,3,4,5]sum [1,2,3,4,5]product [1,2,3,4,5]cycle [1,2,3]repeat 9iterate (1+) 0takeWhile (<3) [1,2,3,4,5]dropWhile (<3) [1,2,3,4,5]splitAt 3 [1,2,3,4,5]any (<5) [1,2,3,4,5]all even [2,4,6,8][x*2 | x <- [0..], x*2 < 9]

zip [1,2,3] [10,11,12]

Page 53: Fertile Ground: The Roots of Clojure

take 2 [1,2,3,4,5]drop 2 [1,2,3,4,5]sum [1,2,3,4,5]product [1,2,3,4,5]cycle [1,2,3]repeat 9iterate (1+) 0takeWhile (<3) [1,2,3,4,5]dropWhile (<3) [1,2,3,4,5]splitAt 3 [1,2,3,4,5]any (<5) [1,2,3,4,5]all even [2,4,6,8][x*2 | x <- [0..], x*2 < 9]

zip [1,2,3] [10,11,12]

(take 2 [1,2,3,4,5])(drop 2 [1,2,3,4,5])(reduce + [1,2,3,4,5])(reduce * [1,2,3,4,5])(cycle [1,2,3])(repeat 9)(iterate + 0)(take-while #(< 3) [1,2,3,4,5])(drop-while #(< 3) [1,2,3,4,5])(split-at 3 [1,2,3,4,5])(some #(< 5) [1,2,3,4,5])(every? even? [2,4,6,8])(for [x (range) :let [y (* 2 x)] :while (< y 9)] y)(map vector [1,2,3] [10,11,12])

Page 54: Fertile Ground: The Roots of Clojure

laziness

Page 55: Fertile Ground: The Roots of Clojure

- explosion- non-termination- full-realization

Page 56: Fertile Ground: The Roots of Clojure

- explosion

- non-termination

- full-realization

Page 57: Fertile Ground: The Roots of Clojure

windowed

Page 58: Fertile Ground: The Roots of Clojure

monetDB

Page 59: Fertile Ground: The Roots of Clojure
Page 60: Fertile Ground: The Roots of Clojure

- MVCC- Snapshot Isolation

- Transactions

Page 61: Fertile Ground: The Roots of Clojure

set!

set!

set!

set! set!set!

set!

set!

set!

set!

set!

set!

set!

set!

set!set!set!

set!

set!set!

set!set!

Page 62: Fertile Ground: The Roots of Clojure

set!

Page 63: Fertile Ground: The Roots of Clojure

ml

Page 64: Fertile Ground: The Roots of Clojure

set!

val r = ref 5;

!r;> val it = 5 : int

r := !r + 4;

!r;> val it = 9 : int

(def r (ref 5))

@r;=> 5

(dosync (alter r + 4))

@r;=> 9

Page 65: Fertile Ground: The Roots of Clojure
Page 66: Fertile Ground: The Roots of Clojure

-module(counter).-export([init/0, get/1]).

init() -> spawn(fun() -> loop(0) end).

loop(Value) -> receive {get, From} -> From ! Value, loop(Value+1) end.

get(C) -> C ! {get, self()}, receive X -> X end.

Page 67: Fertile Ground: The Roots of Clojure

-module(counter).-export([init/0, get/1]).

init() -> spawn(fun() -> loop(0) end).

loop(Value) -> receive {get, From} -> From ! Value, loop(Value+1) end.

get(C) -> C ! {get, self()}, receive X -> X end.

Process B

receive {get, From} -> From ! Value, loop(Value+1)end.

Page 68: Fertile Ground: The Roots of Clojure

Process B

receive {get, From} -> From ! Value, loop(Value+1)end.

Process A

c(counter).C = counter:init().

counter:get(C).%=> 0

counter:get(C).%=> 1

get

Page 69: Fertile Ground: The Roots of Clojure

Thread A

(def C (agent 0))

(send-off C inc)

@C%=> 1

Thread B

inc (apply inc @C)

Page 70: Fertile Ground: The Roots of Clojure
Page 71: Fertile Ground: The Roots of Clojure

EEK!?

Page 72: Fertile Ground: The Roots of Clojure
Page 73: Fertile Ground: The Roots of Clojure

Thanks To● You

● Rich Hickey

● Relevance

● Chris Houser

● Manning Publishing

● The fam

Page 74: Fertile Ground: The Roots of Clojure

Questions?(example questions below)

● Joel or Mike?● Best zombie movies?● Good writing music?● Parallels between Ornette Coleman

and Clojure?

Page 75: Fertile Ground: The Roots of Clojure

:fred

:ethel

:ricky

:lucy

{:ricky "lucy", :fred "ethel"}

(.toUpper “fred”)

["fred" "ethel" "lucy"]

{:keys [fred ethel lucy]}

{1 “ethel” 2 “fred”}

(m :fred)

#{fred ethel lucy}“Fred”

“Ethel”

“Lucy”

“Ricky”