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
Clojure & ClojureScript
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Stefan Kanev
May 28, 2015
Programming
140
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Clojure & ClojureScript
A presentation at I.T.A.K.E. 2015
Stefan Kanev
May 28, 2015
More Decks by Stefan Kanev
See All by Stefan Kanev
Въведение в (Machine|Deep) Learning
skanev
0
110
GraphQL
skanev
0
470
Automated Testing: Getting it Right
skanev
1
99
From Novice to Expert
skanev
0
460
Inbetween Code and Profession
skanev
0
460
Extreme Programming
skanev
0
830
За смъртта на TDD
skanev
0
640
Python 0 2014
skanev
1
1.8k
Clojure 0 2014
skanev
0
400
Other Decks in Programming
See All in Programming
今さら聞けない .NET CLI
htkym
0
200
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
530
実装をデザインガイドラインに追従させるための取り組み / 260731-dip-mosh-design-system
dachi023
0
5.9k
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
430
Building a Meta Ray-Ban display app
akkeylab
0
170
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
160
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
500
「人を評価する AI」の設計と実装
ryoyanara
0
220
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
330
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
19k
React本体のコードリーディング
high_g_engineer
1
150
片田舎のおっさん、 Swift Buildのダイアモンド問題解決の不具合修正PRを出すが、解決方法がキャッシュをしないようにすることであり、ビルド時間が伸びると言われてマージされないので高速化もする/swiftbuild
yimajo
0
170
Featured
See All Featured
HDC tutorial
michielstock
2
790
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
490
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
300
Designing for Performance
lara
611
70k
Done Done
chrislema
186
16k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.8k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
870
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Mobile First: as difficult as doing things right
swwweet
225
10k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
580
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
490
Optimizing for Happiness
mojombo
378
71k
Transcript
http://xkcd.com/{224,297}
Clojure & ClojureScript Stefan Kanev http://skanev.com/ @skanev I.T.A.K.E. Unconf 26
May 2015 Sofia
None
twitter: @skanev github: skanev blog: http://skanev.com/
Clojure from 10,000 feet
A modern LISP, hosted in the JVM, with a focus
on concurrency
A modern LISP, hosted in the JVM, with a focus
on concurrency
LISP: “that language with the parentheses” also: a subculture
“LISP is too hip, even for me” – a hipster
LISP
None
a * b + c * d (+ (* a
b) (* c d))
homoiconicity data is code, code is data
None
A modern LISP, hosted in the JVM, with a focus
on concurrency
Sans the antiquities: car cdr lambda
Way better design
Less parentheses
A modern LISP, hosted in the JVM, with a focus
on concurrency
Stable platform
Access to full Java ecosystem
Occasionally a huge P.I.T.A.
A modern LISP, hosted in the JVM, with a focus
on concurrency
parallelism vs. concurrency
parallelism Breaking a problem down to smaller parts that can
be computed at the same time
concurrency Synchronising a number of independent processes that are fighting
for the same resources
Syntax
(func arg-1 arg-2 …)
(println "Hello world")
(+ 1 2) (< x y)
(+ 1 2 3 4 5 6) (< u v
w x y z)
(+ (* a b) (* c d)) (+ (* a
b) (* c d))
(defn say-hello [who] (println "Hello" who "!")) (say-hello "Doctor")
OMG Parentheses! Or should I say: ((o) ((m)) (g) (
(( (( (( )) )) )) ))
Parentheses in LISP are not unlike metric time
(defn classify [age] (if (<= 13 age 19) "Teenager" "A
normal person")) (classify 18) ; "Teenager"
(defn factorial [n] (if (= n 1) 1 (* n
(factorial (- n 1)))))
(defn fib [n] (cond (= n 0) 1 (= n
1) 1 :else (+ (fib (- n 1)) (fib (- n 2)))))
(fn [x] (* x 2))
(map (fn [n] (str "Mr. " n)) ["Anderson" "Bond" "Bean"])
; ("Mr. Anderson” ; "Mr. Bond" ; "Mr. Bean")
(filter prime? (range 2 100)) ; (2 3 5 7
11 13 17 19 23 29 31 37 41 ; 43 47 53 59 61 67 71 73 79 83 89 97)
(defn prime? [n] (not-any? (fn [x] (zero? (rem n x)))
(range 2 (inc (Math/sqrt n)))))
Data Structures
maps (hashes) vectors (arrays) sets
immutable
“Modifying” a structure creates a copy containing the change. The
original remains unmodified.
Y
simplicity
multicore ❤ immutable
persistent
The “originals” are maximally reused
a ! (3 2 1)
1 2 3 a a ! (3 2 1)
a ! (3 2 1) b ! (conj a 4)
(4 3 2 1)
1 2 3 a a ! (3 2 1) b
! (4 3 2 1) 4 b 5 c c ! (conj a 5)
Hash Table 1020394597 1020205863 {:foo first, :bar second} first second
Hash Table 1020394597 1020205863 Hash Table 1020394597 1020205863 1021027443 (conj
table :qux 1024)
not that simple
Vectors (“arrays” in other langs)
Vectors are represented by trees Each node has 32 children
log32 … …
… … ⨯
O(?)
log32 n
325 = 33 554 432 326 = 1 073 741
824
“essentially constant time”
None
Software Transactional Memory
concurrency 101
100 € +50 € ⨯2 How much money will the
account have?
300 € 250 €
100 € +50 € = 150 € x2 = 300
€
100 € x2 = 200 € +50 € = 250
€
100 € 200 € 150 € x2 +50 100 €
100 €
100 € 150 € 200 € x2 +50 100 €
100 €
ref
state mutation is modelled as a transaction
if two transactions “get in each others’ way”, one of
them will restart
(def account (ref 100)) ; Thread 1 - Uncle Scrooge
(dosync (alter account (fn [n] (* n 2))) (println "Scrooge: set to " @account)) ; Thread 2 - Donald Duck (dosync (alter account (fn [n] (+ n 50))) (println "Donald: set to " @account))
100 € 300 € 150 € x2 +50 100 €
100 € X x2 150 €
Y
familiar
safe, easy, no deadlocks
Macros
Powerful instrument allowing expressive code
Also known as: the mother of all metaprogramming
Macro Code Some other code
None
doStuff();
Outputs on STDOUT. We want to have the result in
a string instead.
PrintStream original = System.out; ByteArrayOutputStream output = new ByteArrayOutputStream(); try
{ PrintStream fileStream = new PrintStream(output); orgStream = System.out; System.setOut(fileStream); doStuff(); } finally { System.setOut(original); } String output = output.toString();
(do-stuff)
(with-out-str (do-stuff))
(with-out-str (do-stuff))
String output = withOutStr { doStuff(); }
unless
(unless (hungry?) (sleep) (eat)) (if (not (hungry?)) (sleep) (eat))
(defmacro unless [condition consequent alternative] `(if (not ~condition) ~consequent ~alternative))
unless (isHungry()) { sleep(); } else { eat(); }
(cond (= n 0) 1 (= n 1) 1 :else
(+ (fib (- n 2)) (fib (- n 1)))) (if (= n 0) 1 (if (= n 1) 1 (+ (fib (- n 2)) (fib (- n 1)))))
DSL Domain Specific Languages
Transparency
(source if-let) (source await)
ClojureScript
om
Very dynamic
DEMO
REPL Oriented Programming
None