More Related Content Similar to Fertile Ground: The Roots of Clojure Similar to Fertile Ground: The Roots of Clojure (20) Fertile Ground: The Roots of Clojure8. C++'s strong typing has too many
advantages to abandon...
– Rich Hickey
Callbacks in C++ Using Template Functors
“ ”
19. We managed to drag a lot of them
about halfway to Lisp.
– Guy L. Steele
“ ”
39. (def rickey (ref {:in-love? false
:likes [:hates-the-show,
:funny,
:lovely]}))
40. (def lucy (ref {:hates-the-show false,
:funny true,
:lovely true}))
41. (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))
42. (dosync (alter ricky court @lucy))
@rickey
;=> {:in-love? false
:likes [:hates-the-show,
:smart,
:lovely]}
44. (dosync (alter rickey court @lucy))
@rickey
;=> {:in-love? true
:likes [:hates-the-show,
:smart,
:lovely]}
52. 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 9
iterate (1+) 0
takeWhile (<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]
53. 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 9
iterate (1+) 0
takeWhile (<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])
64. 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
67. -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.
68. 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
69. Thread A
(def C (agent 0))
(send-off C inc)
@C
%=> 1
Thread B
inc (apply inc @C)
73. Thanks To
● You
● Rich Hickey
● Relevance
● Chris Houser
● Manning Publishing
● The fam