SlideShare a Scribd company logo
http://xkcd.com/{224,297}
Clojure & ClojureScript
Stefan Kanev
http://skanev.com/
@skanev
I.T.A.K.E. Unconf
26 May 2015
Sofia
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Unconference 2015
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
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Unconference 2015
a * b + c * d
(+ (* a b) (* c d))
homoiconicity
data is code, code is
data
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Unconference 2015
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)
123
a
a ! (3 2 1)
a ! (3 2 1)
b ! (conj a 4)
(4 3 2 1)
123
a
a ! (3 2 1)
b ! (4 3 2 1)
4b
5c
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(?)
log32n
325 = 33 554 432
326 = 1 073 741 824
“essentially constant
time”
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Unconference 2015
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
MacroCode
Some other
code
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Unconference 2015
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)))))
DSLDomain Specific Languages
Transparency
(source if-let)
(source await)
ClojureScript
om
Very dynamic
DEMO
REPL Oriented Programming
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Unconference 2015

More Related Content

PPTX
How i won a golf set from reg.ru
PDF
Short intro to the Rust language
PDF
Input output tables
PDF
Christian Gill ''Functional programming for the people''
DOC
BingoConsoleApp
PDF
Зависимые типы в GHC 8. Максим Талдыкин
PDF
PDF
Laziness in Swift
How i won a golf set from reg.ru
Short intro to the Rust language
Input output tables
Christian Gill ''Functional programming for the people''
BingoConsoleApp
Зависимые типы в GHC 8. Максим Талдыкин
Laziness in Swift

What's hot (20)

PPTX
Python Tidbits
PDF
An Intro To ES6
PDF
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
PPTX
The State of JavaScript
PDF
Adventures In Data Compilation
PPTX
Better performance through Superscalarity
DOCX
BOXPLOT EXAMPLES in R And An Example for BEESWARM:
PPTX
Lambda calculus
PDF
Introduction to programming - class 11
PDF
ECMAScript 6, o cómo usar el JavaScript del futuro hoy
PDF
Simpson and lagranje dalambair math methods
PDF
ECMAScript 6 major changes
PPTX
ES6 in Real Life
PDF
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
KEY
Generating and Analyzing Events
PPT
PyTrening 2.0 # 15 Okienka GUI
PDF
Dev day linux redu
PPTX
Selected Bash shell tricks from Camp CDL breakout group
PDF
Swift - Krzysztof Skarupa
PPTX
Proofs of Work
Python Tidbits
An Intro To ES6
Exploring Color Spaces
 with Gesture Tracking and Smart Bulbs (Distill 2014)
The State of JavaScript
Adventures In Data Compilation
Better performance through Superscalarity
BOXPLOT EXAMPLES in R And An Example for BEESWARM:
Lambda calculus
Introduction to programming - class 11
ECMAScript 6, o cómo usar el JavaScript del futuro hoy
Simpson and lagranje dalambair math methods
ECMAScript 6 major changes
ES6 in Real Life
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
Generating and Analyzing Events
PyTrening 2.0 # 15 Okienka GUI
Dev day linux redu
Selected Bash shell tricks from Camp CDL breakout group
Swift - Krzysztof Skarupa
Proofs of Work
Ad

Similar to Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Unconference 2015 (20)

PDF
Clojure - An Introduction for Lisp Programmers
PDF
I know Java, why should I consider Clojure?
PDF
Pune Clojure Course Outline
PPTX
Clojure 7-Languages
ODP
Clojure basics
PDF
Functional programming with clojure
PDF
Clojure concurrency overview
KEY
Clojure Intro
PDF
Introduction to clojure
PDF
Thinking Functionally with Clojure
PDF
Thinking Functionally - John Stevenson - Codemotion Rome 2017
PPT
PDF
Clojure intro
KEY
(map Clojure everyday-tasks)
PDF
Clojure and The Robot Apocalypse
PDF
Clojure Interoperability
PDF
Clojure values
PDF
Clojure class
PDF
Introduction to Clojure
PDF
Get into Functional Programming with Clojure
Clojure - An Introduction for Lisp Programmers
I know Java, why should I consider Clojure?
Pune Clojure Course Outline
Clojure 7-Languages
Clojure basics
Functional programming with clojure
Clojure concurrency overview
Clojure Intro
Introduction to clojure
Thinking Functionally with Clojure
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Clojure intro
(map Clojure everyday-tasks)
Clojure and The Robot Apocalypse
Clojure Interoperability
Clojure values
Clojure class
Introduction to Clojure
Get into Functional Programming with Clojure
Ad

More from Mozaic Works (20)

PDF
Agile Retrospectives
PDF
Developer Experience to Testing
PDF
Story mapping: build better products with a happier team
PDF
Andrea Mocci: Beautiful Design, Beautiful Coding at I T.A.K.E. Unconference 2015
PDF
Ionuț G. Stan - Let’s write a type checker at I T.A.K.E. Unconference 2015
PDF
Cyrille Martraire: Living Documentation Jumpstart at I T.A.K.E. Unconference ...
PDF
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
PDF
Andrei Petcu: Rocket vs Docker: Battle for the Linux Container at I T.A.K.E. ...
PDF
Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
PDF
Patroklos Papapetrou: How to Boost Development Team’s Speed at I T.A.K.E. Unc...
PDF
Patroklos Papapetrou: Holding Down Your Technical Debt With SonarQube at I T....
PDF
Robert Mircea & Virgil Chereches: Our Journey To Continuous Delivery at I T.A...
PDF
James Lewis: Microservices - Systems That Are #neverdone at I T.A.K.E. Unconf...
PDF
Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference
PDF
Adi Bolboacă: Architecture For Disaster Resistant Systems at I T.A.K.E. Unco...
PDF
Alex Bolboacă: Why You Should Start Using Docker at I T.A.K.E. Unconference ...
PDF
Alex Bolboacă: Usable Software Design at I T.A.K.E. Unconference 2015
PDF
Svetlana Mukhina: Metrics That Bring Value at I T.A.K.E. Unconference 2015
PDF
Aki Salmi: Object Oriented Views at I T.A.K.E. Unconference 2015
PDF
Igor Popov: Mutation Testing at I T.A.K.E. Unconference 2015
Agile Retrospectives
Developer Experience to Testing
Story mapping: build better products with a happier team
Andrea Mocci: Beautiful Design, Beautiful Coding at I T.A.K.E. Unconference 2015
Ionuț G. Stan - Let’s write a type checker at I T.A.K.E. Unconference 2015
Cyrille Martraire: Living Documentation Jumpstart at I T.A.K.E. Unconference ...
Cyrille Martraire: Monoids, Monoids Everywhere! at I T.A.K.E. Unconference 2015
Andrei Petcu: Rocket vs Docker: Battle for the Linux Container at I T.A.K.E. ...
Simon Brown: Software Architecture as Code at I T.A.K.E. Unconference 2015
Patroklos Papapetrou: How to Boost Development Team’s Speed at I T.A.K.E. Unc...
Patroklos Papapetrou: Holding Down Your Technical Debt With SonarQube at I T....
Robert Mircea & Virgil Chereches: Our Journey To Continuous Delivery at I T.A...
James Lewis: Microservices - Systems That Are #neverdone at I T.A.K.E. Unconf...
Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference
Adi Bolboacă: Architecture For Disaster Resistant Systems at I T.A.K.E. Unco...
Alex Bolboacă: Why You Should Start Using Docker at I T.A.K.E. Unconference ...
Alex Bolboacă: Usable Software Design at I T.A.K.E. Unconference 2015
Svetlana Mukhina: Metrics That Bring Value at I T.A.K.E. Unconference 2015
Aki Salmi: Object Oriented Views at I T.A.K.E. Unconference 2015
Igor Popov: Mutation Testing at I T.A.K.E. Unconference 2015

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
Teaching material agriculture food technology
PPTX
A Presentation on Artificial Intelligence
PPTX
Programs and apps: productivity, graphics, security and other tools
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Electronic commerce courselecture one. Pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Cloud computing and distributed systems.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Teaching material agriculture food technology
A Presentation on Artificial Intelligence
Programs and apps: productivity, graphics, security and other tools
The AUB Centre for AI in Media Proposal.docx
Dropbox Q2 2025 Financial Results & Investor Presentation
Advanced methodologies resolving dimensionality complications for autism neur...
Electronic commerce courselecture one. Pdf
A comparative analysis of optical character recognition models for extracting...
Per capita expenditure prediction using model stacking based on satellite ima...
Reach Out and Touch Someone: Haptics and Empathic Computing
Approach and Philosophy of On baking technology
NewMind AI Weekly Chronicles - August'25-Week II
Agricultural_Statistics_at_a_Glance_2022_0.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
cuic standard and advanced reporting.pdf
Encapsulation theory and applications.pdf
Cloud computing and distributed systems.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Unconference 2015