SlideShare a Scribd company logo
Introduction to Functional
Programming and Clojure
@sdaas
What to Expect …
• Look at programming in a different way
– Immutable data
– A world without for-loops
• Understand basics of functional programming
– In the context of Clojure
• A POV on why to consider a functional
programming style in your current project
• And why Clojure might be a good choice
What NOT to Expect …
• NOT a deep dive into all aspects of the Clojure
programming language
• NOT about installation, debugging,
performance, etc. of Clojure
• NO bashing of Java or any other language
• NO bashing of Object-Oriented Design
Don’t forget Java yet …
• FP is a programming paradigm or style
• Some languages lend themselves better to
functional programming
– Clojure, Haskell, Erlang
• Most languages support FP to some extent
– Java 8
– JavaScript
– Python
Functional Programming Concepts
• More like Mathematical Functions
– vs. Subroutines/procedures
• Support higher order functions
• Pure functions – with no side effects
• Recursion is favored over iteration
• Lazy Evaluation
• Referential Transparency
– Once defined, a “variable” never changes value
What is Clojure ?
• Created by Rich Hickey
• Immutable and Functional Programming style
• Lisp that runs on the JVM
• Interoperates with Java
• Power of Functional Programming meets the
Richness of Java Ecosystem
Clojure Syntax
Functions
Lists
• Collection of heterogeneous values
• Operations on lists never modify the original
list. They always return a copy.
• This “immutability” of data structure is a big
deal in Functional Programing.
• Two fundamental operators – first, & rest
• Every data structure and function is built up
using these two operators
Lists
Building Blocks – first & rest
• Favoring recursion over iteration
• Do you see the bomb in the nth-element ?
Tail recursion is your friend
Map, Filter, and Reduce
Composition
• FP encourages you to compose small/simpler
function to create complex functions
What does this code do ?
Sum of square of all odd numbers ..
• How testable and maintainable is this code ?
• Modify this for odd numbers that aren’t multiples of 7 ?
• How would this work for infinitely long data ?
Functional Version …
Find the first 20 prime numbers
Laziness is good ...
• Iterate : returns lazy sequence of f(x) f(f(x)) etc ..
• take : returns a lazy sequence of first n from collection
• Map and filter can work on lazy sequences
• Check out the call to java.lang.Math.sqrt
Hash Maps
Reading a CSV File …
FROM
Smith,John,45,90210
Frank,Peter,25,90110
Bond,James,38,90110
TO
{:zip 90210, :age 45, :fname "John", :lname "Smith"}
{:zip 90110, :age 25, :fname "Peter", :lname "Frank"}
{:zip 90110, :age 38, :fname "James", :lname "Bond"}
12 lines of Clojure Code …
What the %$*&^ was that ?
In Summary …
• FP concepts can be used to create concise,
highly modular, and composable code
• Java 8 and JavaScript have good support for FP
concepts
• Clojure interoperates well with Java, and could
be a good way to experiment with FP without
abandoning the Java ecosystem
Questions ?
Please give your feedback at
http://bit.ly/introfp
Resources
• The SICP Book “Structure and Interpretation of
Computer Programs”
• Paul Graham’s Blogs
• Clojure Home page (clojure.org)
• Clojure for the Brave and True (braveclojure.com)
• www.slideshare.net/SoumendraDaas/present
ations
• www.github.com/sdaas/clojure-talk
• https://medium.com/@sdaas/functionally-
speaking-f4dba2a1c7ee

More Related Content

What's hot (20)

PDF
Erlang workshopdrammen
Reidar Sollid
 
PPTX
Basics of functional Programming by Siddharth Kulkarni
Chandulal Kavar
 
PPTX
Natural Language to Visualization by Neural Machine Translation
ivaderivader
 
ODP
ANTLR4 and its testing
Knoldus Inc.
 
PDF
Technical screening .Net Developer
Tom Henricksen
 
PPTX
C# 8 e além
Lucas Teles
 
PPTX
Java presentation
Md. Taiseen Azam
 
ODP
Using ANTLR on real example - convert "string combined" queries into paramete...
Alexey Diyan
 
PPTX
Craft of coding
Justin Weinberg
 
PDF
OOPS Advanced
Madhavan Malolan
 
PPT
Functional OOP, Clojure style
yoavrubin
 
PDF
Xtext Webinar
Heiko Behrens
 
PPTX
Fine tuning large LMs
SylvainGugger
 
PDF
Object Oriented Programming : Part 2
Madhavan Malolan
 
PDF
Writing readable Clojure code
Jiří Knesl
 
PDF
Why Functional Programming and Clojure - LightningTalk
Jakub Holy
 
PDF
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
Weverton Timoteo
 
PDF
Implementing DSLs in practice
Mikhail Barash
 
PPT
Class9
issbp
 
PDF
Internal domain-specific languages
Mikhail Barash
 
Erlang workshopdrammen
Reidar Sollid
 
Basics of functional Programming by Siddharth Kulkarni
Chandulal Kavar
 
Natural Language to Visualization by Neural Machine Translation
ivaderivader
 
ANTLR4 and its testing
Knoldus Inc.
 
Technical screening .Net Developer
Tom Henricksen
 
C# 8 e além
Lucas Teles
 
Java presentation
Md. Taiseen Azam
 
Using ANTLR on real example - convert "string combined" queries into paramete...
Alexey Diyan
 
Craft of coding
Justin Weinberg
 
OOPS Advanced
Madhavan Malolan
 
Functional OOP, Clojure style
yoavrubin
 
Xtext Webinar
Heiko Behrens
 
Fine tuning large LMs
SylvainGugger
 
Object Oriented Programming : Part 2
Madhavan Malolan
 
Writing readable Clojure code
Jiří Knesl
 
Why Functional Programming and Clojure - LightningTalk
Jakub Holy
 
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
Weverton Timoteo
 
Implementing DSLs in practice
Mikhail Barash
 
Class9
issbp
 
Internal domain-specific languages
Mikhail Barash
 

Similar to Introduction to Functional Programming and Clojure (20)

KEY
Clojure - an introduction (and some CFML)
Kai Koenig
 
PPTX
Into the Land of lambda, One Programmer's Journey Into Functional Programming
Mike Pence
 
PPT
Clojure 1a
Krishna Chaytaniah
 
PDF
Intro to Functional Programming
Hugo Firth
 
PDF
OOP and FP
Mario Fusco
 
PDF
Clojure (and some lisp) in 10 mins for OO developers
Chris F Carroll
 
PDF
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Codemotion
 
PDF
Thinking Functionally with Clojure
John Stevenson
 
PDF
Functional web with clojure
John Stevenson
 
PDF
Clojure intro
Basav Nagur
 
ODP
Clojure
alandipert
 
PDF
Introduction to Clojure
Renzo Borgatti
 
PDF
Introductory Clojure Presentation
Jay Victoria
 
PDF
Get into Functional Programming with Clojure
John Stevenson
 
PDF
Functional Programming in Clojure
Troy Miles
 
PDF
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
Codemotion
 
PDF
Clojure
Rohit Vaidya
 
PDF
Full Stack Clojure
Michiel Borkent
 
PDF
Introduction to clojure
Abbas Raza
 
PDF
Fun with Functional Programming in Clojure
Codemotion
 
Clojure - an introduction (and some CFML)
Kai Koenig
 
Into the Land of lambda, One Programmer's Journey Into Functional Programming
Mike Pence
 
Intro to Functional Programming
Hugo Firth
 
OOP and FP
Mario Fusco
 
Clojure (and some lisp) in 10 mins for OO developers
Chris F Carroll
 
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Codemotion
 
Thinking Functionally with Clojure
John Stevenson
 
Functional web with clojure
John Stevenson
 
Clojure intro
Basav Nagur
 
Clojure
alandipert
 
Introduction to Clojure
Renzo Borgatti
 
Introductory Clojure Presentation
Jay Victoria
 
Get into Functional Programming with Clojure
John Stevenson
 
Functional Programming in Clojure
Troy Miles
 
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
Codemotion
 
Clojure
Rohit Vaidya
 
Full Stack Clojure
Michiel Borkent
 
Introduction to clojure
Abbas Raza
 
Fun with Functional Programming in Clojure
Codemotion
 
Ad

Recently uploaded (20)

PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Import Data Form Excel to Tally Services
Tally xperts
 
Ad

Introduction to Functional Programming and Clojure

  • 2. What to Expect … • Look at programming in a different way – Immutable data – A world without for-loops • Understand basics of functional programming – In the context of Clojure • A POV on why to consider a functional programming style in your current project • And why Clojure might be a good choice
  • 3. What NOT to Expect … • NOT a deep dive into all aspects of the Clojure programming language • NOT about installation, debugging, performance, etc. of Clojure • NO bashing of Java or any other language • NO bashing of Object-Oriented Design
  • 4. Don’t forget Java yet … • FP is a programming paradigm or style • Some languages lend themselves better to functional programming – Clojure, Haskell, Erlang • Most languages support FP to some extent – Java 8 – JavaScript – Python
  • 5. Functional Programming Concepts • More like Mathematical Functions – vs. Subroutines/procedures • Support higher order functions • Pure functions – with no side effects • Recursion is favored over iteration • Lazy Evaluation • Referential Transparency – Once defined, a “variable” never changes value
  • 6. What is Clojure ? • Created by Rich Hickey • Immutable and Functional Programming style • Lisp that runs on the JVM • Interoperates with Java • Power of Functional Programming meets the Richness of Java Ecosystem
  • 9. Lists • Collection of heterogeneous values • Operations on lists never modify the original list. They always return a copy. • This “immutability” of data structure is a big deal in Functional Programing. • Two fundamental operators – first, & rest • Every data structure and function is built up using these two operators
  • 10. Lists
  • 11. Building Blocks – first & rest • Favoring recursion over iteration • Do you see the bomb in the nth-element ?
  • 12. Tail recursion is your friend
  • 14. Composition • FP encourages you to compose small/simpler function to create complex functions
  • 15. What does this code do ?
  • 16. Sum of square of all odd numbers .. • How testable and maintainable is this code ? • Modify this for odd numbers that aren’t multiples of 7 ? • How would this work for infinitely long data ?
  • 18. Find the first 20 prime numbers
  • 19. Laziness is good ... • Iterate : returns lazy sequence of f(x) f(f(x)) etc .. • take : returns a lazy sequence of first n from collection • Map and filter can work on lazy sequences • Check out the call to java.lang.Math.sqrt
  • 21. Reading a CSV File … FROM Smith,John,45,90210 Frank,Peter,25,90110 Bond,James,38,90110 TO {:zip 90210, :age 45, :fname "John", :lname "Smith"} {:zip 90110, :age 25, :fname "Peter", :lname "Frank"} {:zip 90110, :age 38, :fname "James", :lname "Bond"}
  • 22. 12 lines of Clojure Code …
  • 23. What the %$*&^ was that ?
  • 24. In Summary … • FP concepts can be used to create concise, highly modular, and composable code • Java 8 and JavaScript have good support for FP concepts • Clojure interoperates well with Java, and could be a good way to experiment with FP without abandoning the Java ecosystem
  • 25. Questions ? Please give your feedback at http://bit.ly/introfp
  • 26. Resources • The SICP Book “Structure and Interpretation of Computer Programs” • Paul Graham’s Blogs • Clojure Home page (clojure.org) • Clojure for the Brave and True (braveclojure.com) • www.slideshare.net/SoumendraDaas/present ations • www.github.com/sdaas/clojure-talk • https://medium.com/@sdaas/functionally- speaking-f4dba2a1c7ee