Fertile Ground: The Roots of Clojure
-
Upload
mike-fogus -
Category
Technology
-
view
5.815 -
download
1
Transcript of Fertile Ground: The Roots of Clojure
Fertile GroundThe Roots of Clojure
who
1994
C++
C++'s strong typing has too many advantages to abandon...
C++'s strong typing has too many advantages to abandon...– Rich Hickey
Callbacks in C++ Using Template Functors
“ ”
Lisp!
● Interfaces● Sub-typing● Polymorphism● Encapsulation● JVM● Memory model
● Implementation inheritance
● Hierarchies● Kingdom of Nouns● Mutability● Imperative● Very Verbose Verbosity
eschew
We managed to drag a lot of them about halfway to Lisp.– Guy L. Steele
“ ”
C++ LispJava
zeitgeist
kingdom of nouns
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(.
..)
doThis(...)doThat(...)doSomethingElse(...)toThis(...)
toSomethingElse(...)toThat(...)
fromThis(...)
fromSomethingElse(...)fromThat(...)
asThis(...)
asSomethingElse(...)asThat(...)
copy(...)equals(...)add(...)
remove(...)
update(...)compareTo(...)
eat(...)frobnicate(...)
(ns utils)
String
String cat(String that)
String
String cat(String that)
String
String cat(String that)
String
String cat(String that)
StringWrapper
String cat(String that)
String
Concatenatable
Concatenatable
cat(String this, that)String
Concatenatable
cat(String this, that)String List
cat(List this, that)
Concatenatable
cat(String this, that)String List
cat(List this, that)
String[]
cat(String[] this, that)
Object[][]
cat(Object[][] this, that)
subjectivity
(def rickey (ref {:in-love? false :likes [:hates-the-show, :funny, :lovely]}))
(def lucy (ref {:hates-the-show false, :funny true, :lovely true}))
(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))
(dosync (alter ricky court @lucy))
@rickey
;=> {:in-love? false :likes [:hates-the-show, :smart, :lovely]}
(dosync (ref-set lucy {:hates-the-show true, :smart true, :lovely true}))
(dosync (alter rickey court @lucy))
@rickey
;=> {:in-love? true :likes [:hates-the-show, :smart, :lovely]}
?-
TDD
TDDTEST DRIVEN DENTISTRY
thoughtstuff
TDD
T__
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]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])
laziness
- explosion- non-termination- full-realization
- explosion
- non-termination
- full-realization
windowed
monetDB
- MVCC- Snapshot Isolation
- Transactions
set!
set!
set!
set! set!set!
set!
set!
set!
set!
set!
set!
set!
set!
set!set!set!
set!
set!set!
set!set!
set!
ml
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
-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.
-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.
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
Thread A
(def C (agent 0))
(send-off C inc)
@C%=> 1
Thread B
inc (apply inc @C)
EEK!?
Thanks To● You
● Rich Hickey
● Relevance
● Chris Houser
● Manning Publishing
● The fam
Questions?(example questions below)
● Joel or Mike?● Best zombie movies?● Good writing music?● Parallels between Ornette Coleman
and 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”