SlideShare a Scribd company logo
with
by
Carlo Sciollaskuro@skuro.tk
with
Carlo Sciollaskuro@skuro.tk
works for
organisesfrom
The package contains
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
with
with
The package contains
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
with
Brief intro to Clojure
● I will trade precision for clarity
● there’s much more to know
● one huge missing topic: the REPL
● you can try this at home
with
Clojure data anatomy
1 2.0 3/4 ; numbers
foo bar ; symbols
:one :two ; keywords
“value” ; strings
true false ; bools
a b c ; chars
nil ; null
with
Clojure data anatomy
[1 2 3] ; vector
‘(foo bar) ; list
#{:one :two} ; set
{:key “value”} ; map
with
Clojure data anatomy
[1 2 3] ; vector
‘(foo bar) ; list
#{:one :two} ; set
{:key “value”} ; map
with
Clojure code anatomy
(* 132.715
(- 1.06 1.02))
-> 5.308600000000005
nested unquoted lists, in facts:
“The name LISP derives from "LISt Processing".” -- Wikipedia
with
Clojure code anatomy
(* 132.715
(- 1.06 1.02))
-> 5.308600000000005
no “return”: everything
is an expression
with
Clojure beer anatomy
(* 132.715
(- 1.06 1.02))
-> 5.31º
Alcohol by volume formula (Wikipedia):
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
(* 132.715
(- 1.06 1.02))
*
132.
715 -
1.06 1.02
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
(* 132.715
(- 1.06 1.02))
*
132.
715 -
1.06 1.02
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
(* 132.715
(- 1.06 1.02))
STAR
132.
715 -
1.06 1.02
The symbol * evaluates to:
clojure.core/_STAR_
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
(* 132.715
(- 1.06 1.02))
STAR
132.
715 -
1.06 1.02
Values evaluate to themselves
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
(* 132.715
(- 1.06 1.02))
STAR
132.
715 -
1.06 1.02
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
(* 132.715
(- 1.06 1.02))
STAR
132.
715
SUB
1.06 1.02
The symbol - evaluates to:
clojure.core/_
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
(* 132.715
(- 1.06 1.02))
STAR
132.
715
SUB
1.06 1.02
Values evaluate to themselves
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
(* 132.715
(- 1.06 1.02))
STAR
132.
715
SUB
1.06 1.02
Values evaluate to themselves
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
(* 132.715
(- 1.06 1.02))
STAR
132.
715
SUB
1.06 1.02
All args evaluated? Function call!
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
(* 132.715
(- 1.06 1.02))
STAR
132.
715
0.04
All args evaluated? Function call!
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
(* 132.715
(- 1.06 1.02))
STAR
132.
715
0.04
All args evaluated? Function call!
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
5.31
(* 132.715
(- 1.06 1.02))
All args evaluated? Function call!
with
The Reader
Or:
How
I
Learned
To
Stop
Worrying
And
Love
The
Eval
(* 132.715
(- 1.06 1.02))
with
Naming stuff: global bindings
(def scalar 42)
(def fun
(fn [a b] (+ a b)))
(defn moar-fun [a b]
(+ a b)))
with
Naming stuff: lexical bindings
(let [one “one”
key (keyword one)]
key)
; => :one
with
Ready to go
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
(defn compose [f g]
(fn [x] (f (g x))))
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
(defn compose [f g]
(fn [x] (f (g x))))
returns a function
accepts functions in input
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
(defn compose [f g]
(fn [x] (f (g x))))
((compose inc dec) 42)
; => 42
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
(let [foo [{:pi 3.14}
{:g 9.8}]]
(conj foo {:phi 1.62}))
; => [{:pi 3.14} {:g 9.8} {:phi 1.63}]
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
(let [foo [{:pi 3.14}
{:g 9.8}]]
(conj foo {:phi 1.62})
(count foo)) ; => 2
3.14:pi
foo foo’
9.8:g 1.62:phi
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
(doseq [_ (range 2000)]
(inc 41)) ; => always 42
For a given input, pure functions yield the same result,
making them dead-easy to maintain and prove correct
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
(doseq [_ (range 2000)]
(rand)
(http/GET “http://...”))
Impure code enables interaction, but introduces side effects
which make your program harder to test and reason about
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
(defn my-inc [[h & t]]
(when h
(cons (inc h)
(my-inc t))))
recursive call
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
(defn my-inc [[h & t]]
(when h
(cons (inc h)
(my-inc t))))exit condition
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
destructuring:
pattern-match your input
(defn my-inc [[h & t]]
(when h
(cons (inc h)
(my-inc t))))
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
def my-inc(s) {
def res = []
for(i in s)
res << i + 1
res
}
(defn my-inc [[h & t]]
(when h
(cons (inc h)
(my-inc t))))
with
What if the input is infinite?
(defn my-inc [[h & t]]
(when h
(cons (inc h)
(my-inc t))))
with
Kaboom!
(defn my-inc [[h & t]]
(when h
(cons (inc h)
(my-inc t))))
with no tail call optimisation (TCO),
recursive invocations blows up the stack
with
Working around the lack of TCO
(defn my-inc [s]
(loop [res () rem s]
(let [[h & t] rem]
(if h
(recur (cons (inc h) res) t)
res))))
with
Working around the lack of TCO
(defn my-inc [s]
(loop [res () rem s]
(let [[h & t] rem]
(if h
(recur (cons (inc h) res) t)
res))))
ECMAScript 6
Java 9 (?)
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
(defn lazy-inc [[h & t]]
(lazy-seq
(when h
(cons (inc h)
(lazy-inc t))))
with
Functional schmunctional
● functions as values
● immutable (persistent) data structures
● pure functions
● recursion
● lazy evaluation
(defn lazy-inc [[h & t]]
(lazy-seq
(when h
(cons (inc h)
(lazy-inc t))))
retuns a “thunk”
with
What if the input is infinite?
(defn lazy-inc [[h & t]]
(lazy-seq
(when h
(cons (inc h)
(lazy-inc t)))))
with
What if the input is infinite?
(defn lazy-inc [[h & t]]
(lazy-seq
(when h
(cons (inc h)
(lazy-inc t)))))
with
Q / A
with
Thanks!
Carlo Sciolla
p r o f e s s i o n a l t i n k e r e r
https://twitter.com/skuro
https://github.com/skuro
http://skuro.tk
http://amsclj.nl

More Related Content

What's hot (20)

PDF
R Programming: Transform/Reshape Data In R
Rsquared Academy
 
PDF
Scala for Java Developers
Martin Ockajak
 
PDF
Comparing Haskell & Scala
Martin Ockajak
 
PDF
R factors
Learnbay Datascience
 
PDF
Refinement Types for Haskell
Martin Ockajak
 
PDF
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
tdc-globalcode
 
ODP
Clojure basics
Knoldus Inc.
 
PDF
Functional programming basics
openbala
 
PPTX
Curry functions in Javascript
Anand Kumar
 
PDF
Scala categorytheory
Knoldus Inc.
 
PDF
20140427 parallel programming_zlobin_lecture11
Computer Science Club
 
PDF
Data structure lab manual
nikshaikh786
 
PPTX
Functional programming in JavaScript
Joseph Smith
 
PDF
SeaJUG March 2004 - Groovy
Ted Leung
 
PPTX
Function composition in Javascript
Anand Kumar
 
PPTX
Functional Programming in Javascript - IL Tech Talks week
yoavrubin
 
PPT
C++ Returning Objects
Jay Patel
 
PPTX
Yin Yangs of Software Development
Naveenkumar Muguda
 
PDF
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Brendan Eich
 
PPTX
“Tasks” in NetLogo 5.0beta1
SethTisue
 
R Programming: Transform/Reshape Data In R
Rsquared Academy
 
Scala for Java Developers
Martin Ockajak
 
Comparing Haskell & Scala
Martin Ockajak
 
Refinement Types for Haskell
Martin Ockajak
 
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
tdc-globalcode
 
Clojure basics
Knoldus Inc.
 
Functional programming basics
openbala
 
Curry functions in Javascript
Anand Kumar
 
Scala categorytheory
Knoldus Inc.
 
20140427 parallel programming_zlobin_lecture11
Computer Science Club
 
Data structure lab manual
nikshaikh786
 
Functional programming in JavaScript
Joseph Smith
 
SeaJUG March 2004 - Groovy
Ted Leung
 
Function composition in Javascript
Anand Kumar
 
Functional Programming in Javascript - IL Tech Talks week
yoavrubin
 
C++ Returning Objects
Jay Patel
 
Yin Yangs of Software Development
Naveenkumar Muguda
 
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Brendan Eich
 
“Tasks” in NetLogo 5.0beta1
SethTisue
 

Viewers also liked (20)

PDF
How to Create things people Love-Edward Boudrot
Edward Boudrot
 
PDF
Codigo procesal - proyecto
Mendoza Post
 
PPTX
Blackbaud Webinar: Turning Fans into Donors and Activists Through Social Media
Carie Lewis Carlson
 
PDF
The Century Project Grand Junction, Colorado
tgvku91
 
PDF
Color Grids, 7/6/2011
tgvku91
 
PDF
CTG Ed 542_T-28-29
Hafizh Fauzan
 
PPTX
Distributed Pair Programming
Agile Dimensions LLC
 
PDF
Social Marketing Strategy Electronics Industry
Marcel Baron
 
PPT
Want Your Carpets To Look Like New?
Phoenix 21 LLC Cleaning Service
 
PPTX
Process Automation Makeover: Transform Multiple Workflows into One Process by...
Salesforce Admins
 
PDF
What is engineering_leaflet
izzet-kamil
 
PDF
RESIDUAL INCOME
makemoneyleaders
 
PDF
Resumo cubo rubiks
João Silva
 
PDF
Vanvasa resort
Vanvasa Resort
 
PDF
JFDI: how to get into a top accelerator
Elena Arens
 
PDF
Going viral
FINN
 
PPTX
Impacto de las tic en nuestra institucion educativa
discover2012
 
PDF
ICC World Cup 2015 Logo
Logo Design Guru
 
PPS
同志為什麼要保障?
lalacamp07
 
How to Create things people Love-Edward Boudrot
Edward Boudrot
 
Codigo procesal - proyecto
Mendoza Post
 
Blackbaud Webinar: Turning Fans into Donors and Activists Through Social Media
Carie Lewis Carlson
 
The Century Project Grand Junction, Colorado
tgvku91
 
Color Grids, 7/6/2011
tgvku91
 
CTG Ed 542_T-28-29
Hafizh Fauzan
 
Distributed Pair Programming
Agile Dimensions LLC
 
Social Marketing Strategy Electronics Industry
Marcel Baron
 
Want Your Carpets To Look Like New?
Phoenix 21 LLC Cleaning Service
 
Process Automation Makeover: Transform Multiple Workflows into One Process by...
Salesforce Admins
 
What is engineering_leaflet
izzet-kamil
 
RESIDUAL INCOME
makemoneyleaders
 
Resumo cubo rubiks
João Silva
 
Vanvasa resort
Vanvasa Resort
 
JFDI: how to get into a top accelerator
Elena Arens
 
Going viral
FINN
 
Impacto de las tic en nuestra institucion educativa
discover2012
 
ICC World Cup 2015 Logo
Logo Design Guru
 
同志為什麼要保障?
lalacamp07
 
Ad

Similar to Functional Programming with Clojure (20)

PDF
Clojure
Rohit Vaidya
 
PDF
Python lecture 05
Tanwir Zaman
 
PDF
Functional programming with clojure
Lucy Fang
 
PPS
CS101- Introduction to Computing- Lecture 29
Bilal Ahmed
 
PDF
Functional Programming
Yuan Wang
 
PPTX
Programming picaresque
Bret McGuire
 
PDF
A taste of Functional Programming
Jordan Open Source Association
 
PDF
Power of functions in a typed world
Debasish Ghosh
 
PPT
Profiling and optimization
g3_nittala
 
PDF
Pune Clojure Course Outline
Baishampayan Ghose
 
PDF
The Logical Burrito - pattern matching, term rewriting and unification
Norman Richards
 
PDF
C# - What's Next?
Christian Nagel
 
KEY
Functional programming in clojure
Juan-Manuel Gimeno
 
PDF
Meetup C++ A brief overview of c++17
Daniel Eriksson
 
PPTX
Good functional programming is good programming
kenbot
 
PDF
Functional go
Geison Goes
 
PDF
Functional Go
Geison Goes
 
PDF
The Ring programming language version 1.8 book - Part 37 of 202
Mahmoud Samir Fayed
 
ODP
Scala ntnu
Alf Kristian Støyle
 
Clojure
Rohit Vaidya
 
Python lecture 05
Tanwir Zaman
 
Functional programming with clojure
Lucy Fang
 
CS101- Introduction to Computing- Lecture 29
Bilal Ahmed
 
Functional Programming
Yuan Wang
 
Programming picaresque
Bret McGuire
 
A taste of Functional Programming
Jordan Open Source Association
 
Power of functions in a typed world
Debasish Ghosh
 
Profiling and optimization
g3_nittala
 
Pune Clojure Course Outline
Baishampayan Ghose
 
The Logical Burrito - pattern matching, term rewriting and unification
Norman Richards
 
C# - What's Next?
Christian Nagel
 
Functional programming in clojure
Juan-Manuel Gimeno
 
Meetup C++ A brief overview of c++17
Daniel Eriksson
 
Good functional programming is good programming
kenbot
 
Functional go
Geison Goes
 
Functional Go
Geison Goes
 
The Ring programming language version 1.8 book - Part 37 of 202
Mahmoud Samir Fayed
 
Ad

More from Carlo Sciolla (6)

PDF
Codemotion Amsterdam: a conference for the tech community
Carlo Sciolla
 
PDF
Grudging monkeys and microservices
Carlo Sciolla
 
KEY
Dispatch in Clojure
Carlo Sciolla
 
PDF
A Dive Into Clojure
Carlo Sciolla
 
PDF
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Carlo Sciolla
 
KEY
Alfresco the clojure way
Carlo Sciolla
 
Codemotion Amsterdam: a conference for the tech community
Carlo Sciolla
 
Grudging monkeys and microservices
Carlo Sciolla
 
Dispatch in Clojure
Carlo Sciolla
 
A Dive Into Clojure
Carlo Sciolla
 
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Carlo Sciolla
 
Alfresco the clojure way
Carlo Sciolla
 

Recently uploaded (20)

PDF
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
 
PPTX
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
 
PDF
Telemedicine App Development_ Key Factors to Consider for Your Healthcare Ven...
Mobilityinfotech
 
PPTX
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
 
PDF
Writing Maintainable Playwright Tests with Ease
Shubham Joshi
 
PPTX
arctitecture application system design os dsa
za241967
 
PDF
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
PPTX
Android Notifications-A Guide to User-Facing Alerts in Android .pptx
Nabin Dhakal
 
PDF
Automated Testing and Safety Analysis of Deep Neural Networks
Lionel Briand
 
PPTX
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
PPTX
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
 
PPTX
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
 
PDF
Best Software Development at Best Prices
softechies7
 
PPTX
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
 
PPTX
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
 
PDF
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
 
PDF
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
PPTX
Agentforce – TDX 2025 Hackathon Achievement
GetOnCRM Solutions
 
PDF
Rewards and Recognition (2).pdf
ethan Talor
 
PDF
Automated Test Case Repair Using Language Models
Lionel Briand
 
From Data Preparation to Inference: How Alluxio Speeds Up AI
Alluxio, Inc.
 
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
 
Telemedicine App Development_ Key Factors to Consider for Your Healthcare Ven...
Mobilityinfotech
 
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
 
Writing Maintainable Playwright Tests with Ease
Shubham Joshi
 
arctitecture application system design os dsa
za241967
 
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
Android Notifications-A Guide to User-Facing Alerts in Android .pptx
Nabin Dhakal
 
Automated Testing and Safety Analysis of Deep Neural Networks
Lionel Briand
 
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
IObit Driver Booster Pro Crack Download Latest Version
chaudhryakashoo065
 
Foundations of Marketo Engage - Programs, Campaigns & Beyond - June 2025
BradBedford3
 
Best Software Development at Best Prices
softechies7
 
CV-Project_2024 version 01222222222.pptx
MohammadSiddiqui70
 
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
 
Why Edge Computing Matters in Mobile Application Tech.pdf
IMG Global Infotech
 
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
Agentforce – TDX 2025 Hackathon Achievement
GetOnCRM Solutions
 
Rewards and Recognition (2).pdf
ethan Talor
 
Automated Test Case Repair Using Language Models
Lionel Briand
 

Functional Programming with Clojure