Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Zero to Clojure in 90 minutes
Search
Colin Jones
August 11, 2010
Programming
0
110
Zero to Clojure in 90 minutes
A presentation/workshop at Agile 2010
Colin Jones
August 11, 2010
Tweet
Share
More Decks by Colin Jones
See All by Colin Jones
A Bug's Life: What if `select` is Broken After All?
trptcolin
0
140
Underestimated costs of microservice architectures
trptcolin
3
1.5k
FP vs. OOP: Beyond the Bikeshed
trptcolin
0
390
Diving into the Details with DTrace! (RubyConf 2016 edition)
trptcolin
2
340
Diving into the Details with DTrace
trptcolin
3
490
Adopting FP: the good, the familiar, and the unknown
trptcolin
0
160
Finding out what's *really* going on, with DTrace!
trptcolin
1
320
Beyond top: Command-Line Monitoring on the JVM (ClojureRemote)
trptcolin
0
120
Beyond top: Command-Line Monitoring on the JVM (JavaOne 2015)
trptcolin
1
650
Other Decks in Programming
See All in Programming
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
390
Identifying User Idenity
moro
6
7.9k
gopls を改造したら開発生産性が高まった
satorunooshie
8
240
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
Golang と Erlang
taiyow
8
1.9k
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
140
のびしろを広げる巻き込まれ力:偶然を活かすキャリアの作り方/oso2024
takahashiikki
1
410
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
270
Progressive Web Apps für Desktop und Mobile mit Angular (Hands-on)
christianliebel
PRO
0
110
qmuntal/stateless のススメ
sgash708
0
120
VR HMDとしてのVision Pro+ゲーム開発について
yasei_no_otoko
0
100
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
440
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
790
Speed Design
sergeychernyshev
24
570
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
228
52k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Designing Experiences People Love
moore
138
23k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
231
17k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Docker and Python
trallard
40
3.1k
The Cost Of JavaScript in 2023
addyosmani
45
6.6k
Transcript
Zero to Clojure in 90 Minutes Colin Jones Software Craftsman
at 8th Light @trptcolin Thursday, August 12, 2010
What is Clojure? Thursday, August 12, 2010
(It’s a Lisp) Thursday, August 12, 2010
It runs on the JVM Thursday, August 12, 2010
Created in 2007 by Rich Hickey Thursday, August 12, 2010
Why should we care? Thursday, August 12, 2010
Learning is good. Thursday, August 12, 2010
Concurrency can be scary. Thursday, August 12, 2010
Side effects can cause a mess. Thursday, August 12, 2010
Functional programming can help Thursday, August 12, 2010
Syntax & Data Structures Thursday, August 12, 2010
Expressions (doc +) (find-doc “regex”) Thursday, August 12, 2010
Numbers Integer 42 Long 9999999999999 BigInteger 9999999999999999999 Double 4.2 BigDecimal
4000.2M Ratio 1/3 Thursday, August 12, 2010
More String “go to the” Character \p \a \r \k
Regex #”\d+” Nil nil Boolean true false Keyword :really/soon Symbol some-time Thursday, August 12, 2010
Collections List (1 2 3 4 5) Vector [1 2
3 4 5] Map {:first-name “colin”, :last-name “jones”} Set #{a b c d e} Thursday, August 12, 2010
Expressions (doc +) (find-doc “regex”) Thursday, August 12, 2010
Diving in Thursday, August 12, 2010
Clojure Functional Koans http://trptcolin.github.com USB Drives Thursday, August 12, 2010
REPL => Read => Evaluate => Print Thursday, August 12,
2010
java -jar /path/to/clojure.jar (+ JRE functional-koans) => WIN! From Functional
Koans directory: Mac / Linux: ./repl.sh Windows: repl From anywhere: Thursday, August 12, 2010
Functions Thursday, August 12, 2010
clojure.test user=> (is (= 1 2)) FAIL in clojure.lang.PersistentList$EmptyList@1 15)
expected: (= 1 2) actual: (not (= 1 2)) false user=> (use ‘clojure.test) nil user=> (is (= 1 1)) true Thursday, August 12, 2010
Equality user=> (is (= “Colin” “Colin”)) true user=> (is (=
nil nil)) true user=> (is (= ‘(1 2 3) [1 2 3])) true user=> (is (= 1.0 1 4/4)) true Thursday, August 12, 2010
Math fun(ctions) user=> (is (= 15 (+ 1 2 3
4 5))) true user=> (is (< 1 2 3)) true Thursday, August 12, 2010
Hide and seq? user=> (is (= :a (first [:a :b
:c]))) true user=> (is (= [:c :b :a] (reverse [:a :b :c]))) true user=> (is (= [:b :c] (rest [:a :b :c]))) true Thursday, August 12, 2010
Defining our own functions user=> (def square-1 (fn [x] (*
x x))) #‘user/square-1 user=> (defn square-3 [x] (* x x)) #‘user/square-3 user=> (def square-2 #(* % %)) #‘user/square-2 user=> (is (= 9 (square-1 3))) true user=> (is (= 9 (square-2 3))) true user=> (is (= 9 (square-3 3))) true Thursday, August 12, 2010
map user=> (defn square [x] (* x x)) #‘user/square user=>
(is (= ‘(1 4 9 16 25) (map square ‘(1 2 3 4 5)))) true Thursday, August 12, 2010
filter user=> (is (= [odd?] (filter fn? [“odd” :odd odd?])))
true Thursday, August 12, 2010
apply user=> (is (= “dog” (str \d \o \g))) true
user=> (is (= “dog” (str dog-letters))) FAIL in clojure.lang.PersistentList$EmptyList expected: (= “dog” (str dog-letters)) actual: (not (= “dog” “[\\d \\o \\g]”)) false user=> (def dog-letters [\d \o \g]) true user=> (is (= “dog” (apply str dog-letters))) true Thursday, August 12, 2010
Laziness Thursday, August 12, 2010
The whole numbers user=> (def whole-numbers (iterate inc 0)) #‘user/whole-numbers
user=> (is (= (range 20 40) (take 20 (drop 20 whole-numbers)))) true user=> (is (= (range 0 20) (take 20 whole-numbers))) true Thursday, August 12, 2010
Let’s try it in the REPL user=> (def whole-numbers (iterate
inc 0)) #‘user/whole-numbers user=> whole-numbers (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 OH NOEZ!!! Thursday, August 12, 2010
Don’t hold onto your head user=> (def whole-numbers (iterate inc
0)) #‘user/whole-numbers user=> (first (drop 10000000 whole-numbers)) Exception in thread "main" java.lang.OutOfMemoryError: Java heap space user=> (defn whole-numbers [] (iterate inc 0)) #'user/whole-numbers user=> (first (drop 10000000 (whole-numbers))) 10000000 Thursday, August 12, 2010
BIG NUMBERS!!! Thursday, August 12, 2010
Clojure Functional Koans Thursday, August 12, 2010
Background Aaron Bedra of Relevance based on EdgeCase’s Ruby Koans
Thursday, August 12, 2010
Towards Clojure Enlightement Mac / Linux: ./run.sh Windows: run Thursday,
August 12, 2010
Managing State Thursday, August 12, 2010
vars user=> (def x 42) #‘user/x user=> (let [x :foo]
x) :foo user=> x 42 user=> x 42 Thursday, August 12, 2010
refs user=> (def attendees (ref 30)) #‘user/attendees user=> attendees #<Ref@343aff84:
30> user=> @attendees 30 user=> (alter attendees dec) java.lang.IllegalStateException: No transaction running user=> (dosync (alter attendees dec)) 29 user=> @attendees 29 Thursday, August 12, 2010
refs (defn transfer [amount a b] (dosync (alter a -
amount) (alter b + amount))) (def checking (ref 10)) (def savings (ref 50)) Bank Accounts Branch (transfer 25 checking savings) snapshot (checking=10, savings=50) checking = 60, savings=0 ATM (transfer 25 checking savings) snapshot (checking=10, savings=50) commit (checking=35, savings=25) Conflict discovered! (transfer 25 checking savings) Automatic Retry: commit (checking=60, savings=0) snapshot (checking=35, savings=25) Thursday, August 12, 2010
Further Study Thursday, August 12, 2010
Books Thursday, August 12, 2010
The Internets Functional Koans http://github.com/relevance/functional-koans/tree/clojure Web docs http://clojure.org/ Google Group
http://groups.google.com/group/clojure IRC #clojure on freenode.net Thursday, August 12, 2010
Questions? Thursday, August 12, 2010
Uncle Bob Martin, Corey Haines, Dave Astels, Ken Auer, Chad
Fowler, Keavy McMinn, Michael Feathers, Doug Bradbury, Enrique Comba Riepenhausen, and more... Thursday, August 12, 2010