SlideShare a Scribd company logo
On Functional Programming
   A Clojurian Perspective

         Raju Gandhi
Disclaimers
Disclaimers


I tend to speak fast
Disclaimers


I tend to speak fast
I may have an accent
(struct-map Speaker
:name "raju",
:pronunciation "/raa-jew/",
:description ["java/ruby developer",
              "technophile",
              "language geek"],
:profiles {:twitter "looselytyped"
           :facebook "raju.gandhi"})
About us...

Small consulting/training/mentoring shop
Based out of Ohio and Arizona
Specialize in open-source technologies -
Java/Ruby/Rails/Groovy/Grails
Clojure?

Lisp on the JVM
Dynamic
Excellent concurrency support
Strong Java inter-op
Lazy*
Clojure Syntax


  A whirlwind tour
Clojure Syntax
;lists - these are special
'(+ 1 2 1/3)
;a comment
["this" "is" "a" "vector"]
;commas are whitespace
{:yes true, :no false, :null nil}
;sets
#{a e i o u}
Clojure Syntax
;lists - these are special
'(+ 1 2 1/3)
;a comment
["this" "is" "a" "vector"]
;commas are whitespace
{:yes true, :no false, :null nil}
;sets
#{a e i o u}
Clojure Syntax
;lists - these are special
'(+ 1 2 1/3)
;a comment
["this" "is" "a" "vector"]
;commas are whitespace
{:yes true, :no false, :null nil}
;sets
#{a e i o u}
Clojure Syntax
;lists - these are special
'(+ 1 2 1/3)
;a comment
["this" "is" "a" "vector"]
;commas are whitespace
{:yes true, :no false, :null nil}
;sets
#{a e i o u}
Clojure Syntax
;lists - these are special
'(+ 1 2 1/3)
;a comment
["this" "is" "a" "vector"]
;commas are whitespace
{:yes true, :no false, :null nil}
;sets
#{a e i o u}
LISt Processing
;can be a regular function
;Yes! + is a function :)
(+ 1 2 3)
;or a special form
(if (< x 3) "less than 3" "or not")
;or a macro
(defn say-hello [name]
  (str "Hello, " name))
LISt Processing
;can be a regular function
;Yes! + is a function :)
(+ 1 2 3)
;or a special form
(if (< x 3) "less than 3" "or not")
;or a macro
(defn say-hello [name]
  (str "Hello, " name))
LISt Processing
;can be a regular function
;Yes! + is a function :)
(+ 1 2 3)
;or a special form
(if (< x 3) "less than 3" "or not")
;or a macro
(defn say-hello [name]
  (str "Hello, " name))
LISt Processing
;can be a regular function
;Yes! + is a function :)
(+ 1 2 3)
;or a special form
(if (< x 3) "less than 3" "or not")
;or a macro
(defn say-hello [name]
  (str "Hello, " name))
LISt Processing
;can be a regular function
;Yes! + is a function :)
(+ 1 2 3)
;or a special form
(if (< x 3) "less than 3" "or not")
;or a macro
(defn say-hello [name]
  (str "Hello, " name))
LISt Processing
;can be a regular function
;Yes! + is a function :)
(+ 1 2 3)
;or a special form
(if (< x 3) "less than 3" "or not")
;or a macro
(defn say-hello [name]
  (str "Hello, " name))
LISt Processing
;can be a regular function
;Yes! + is a function :)
(+ 1 2 3)
;or a special form
(if (< x 3) "less than 3" "or not")
;or a macro
(defn say-hello [name]
  (str "Hello, " name))
Homoiconicity

;defining a function
(defn say-hello [name]
  (str "Hello, " name))
Homoiconicity

;defining a function
(defn say-hello [name]
  (str "Hello, " name))
Homoiconicity

;defining a function
(defn say-hello [name]
  (str "Hello, " name))
Homoiconicity

;defining a function
(defn say-hello [name]
  (str "Hello, " name))
Homoiconicity



code == data
What is FP?
What is FP?

What is OOP???
What is FP?

What is OOP???
Functional programming
What is FP?

What is OOP???
Functional programming
 Functions are first class citizens
Why FP?

Compartmentalize
Better re-use
Referential Transparency
 Easier to test
Easier to parallelize
Clojure’s Approach

 Side effects are explicit
 State manipulation via
  Persistent data-structures
  Multiple reference types with
  appropriate semantics
Declaring Functions

;explicit definition
(defn times-2
  "Multiplies its arg by 2"
  [n]
  (* 2 n))
Declaring Functions


;alternate approach
;no docs though
(def times-2
     (fn [n] (* 2 n)))
Declaring Functions



;anonymous function
(map #(* 2 %) [1 2 3])
Declaring Functions



;anonymous function
(map #(* 2 %) [1 2 3])
Consuming Functions


;map takes ([f coll] ...)
(map times-2 [1 2 3])
;> (2 4 6)
Consuming Functions


;map takes ([f coll] ...)
(map #(* 2 %) [1 2 3])
;> (2 4 6)
Consuming Functions


;reduce takes ([f coll] ...)
(reduce + [1 2 3])
;> 6
Functions Everywhere

([4 5 6] 0)
;> 4
(#{a e i o u} a)
;> a
({:yes true, :no false, :null nil} :yes)
;> true
(:yes {:yes true, :no false, :null nil})
;> true
A Small Digression


(let [x 1, y 2] (str x " " y))
;> ”1 2”
(let [[x y] [1 2]] (str x " " y))
;> "1 2"
(let [[x & more] [1 2 3]] (str x " " more))
;> "1 (2 3)"
Looping
(defn min-in-coll [x & more]
  (loop [min x
          [f & others] more]
    (if f
      (recur (if (< min f) min f) others)
      min)))

;(min-in-coll [3 4 2 -1])
;> -1
Thanks!

More Related Content

PDF
Java Cheat Sheet
PPTX
Perl6 a whistle stop tour
PDF
Perl6 a whistle stop tour
PDF
AST + Better Reflection (PHP Benelux 2016 Unconference)
PDF
Php&redis presentation
PPSX
Tuga IT 2017 - What's new in C# 7
PPSX
What's New In C# 7
PDF
PHP Static Code Review
Java Cheat Sheet
Perl6 a whistle stop tour
Perl6 a whistle stop tour
AST + Better Reflection (PHP Benelux 2016 Unconference)
Php&redis presentation
Tuga IT 2017 - What's new in C# 7
What's New In C# 7
PHP Static Code Review

What's hot (19)

KEY
Code as data as code.
PDF
Opa presentation at GamesJs
PPTX
Android Guava
PDF
Javascript development done right
PPTX
Introduzione a C#
PDF
The Macronomicon
PPTX
Linq introduction
PDF
The Ring programming language version 1.7 book - Part 35 of 196
KEY
Clojure入門
PDF
Rakudo
PDF
String functions
PDF
PDF
Elm: give it a try
PDF
Fun never stops. introduction to haskell programming language
PPT
Mixing functional and object oriented approaches to programming in C#
PDF
Refactoring to Macros with Clojure
PDF
Cycle.js: Functional and Reactive
PPTX
Intro to F#
Code as data as code.
Opa presentation at GamesJs
Android Guava
Javascript development done right
Introduzione a C#
The Macronomicon
Linq introduction
The Ring programming language version 1.7 book - Part 35 of 196
Clojure入門
Rakudo
String functions
Elm: give it a try
Fun never stops. introduction to haskell programming language
Mixing functional and object oriented approaches to programming in C#
Refactoring to Macros with Clojure
Cycle.js: Functional and Reactive
Intro to F#
Ad

Viewers also liked (6)

PPT
für dilay
PPT
WordCamp Romania 2010 - mobile web si WordPress
PPT
Web Analytics
PPTX
Fran Mancia Use/Creation JPAs
PDF
Brochure
PDF
Ky Nang Giao Quyen
für dilay
WordCamp Romania 2010 - mobile web si WordPress
Web Analytics
Fran Mancia Use/Creation JPAs
Brochure
Ky Nang Giao Quyen
Ad

Similar to On Functional Programming - A Clojurian Perspective (20)

KEY
Clojure Intro
PDF
Clojure class
PPT
PDF
Clojure
PDF
Clojure intro
ODP
Clojure: Practical functional approach on JVM
PDF
Clojure values
PDF
Introduction to clojure
PDF
Get into Functional Programming with Clojure
PDF
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
PDF
PPTX
Clojure 7-Languages
PDF
Thinking Functionally with Clojure
PDF
Thinking Functionally - John Stevenson - Codemotion Rome 2017
PPTX
Introduction to Clojure and why it's hot for Sart-Ups
PDF
Fun with Functional Programming in Clojure
PDF
Introductory Clojure Presentation
PDF
Clojure: Functional Concurrency for the JVM (presented at OSCON)
PDF
(first '(Clojure.))
PDF
Pune Clojure Course Outline
Clojure Intro
Clojure class
Clojure
Clojure intro
Clojure: Practical functional approach on JVM
Clojure values
Introduction to clojure
Get into Functional Programming with Clojure
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
Clojure 7-Languages
Thinking Functionally with Clojure
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Introduction to Clojure and why it's hot for Sart-Ups
Fun with Functional Programming in Clojure
Introductory Clojure Presentation
Clojure: Functional Concurrency for the JVM (presented at OSCON)
(first '(Clojure.))
Pune Clojure Course Outline

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Network Security Unit 5.pdf for BCA BBA.
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Machine learning based COVID-19 study performance prediction
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
KodekX | Application Modernization Development
PDF
Spectral efficient network and resource selection model in 5G networks
Chapter 3 Spatial Domain Image Processing.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Network Security Unit 5.pdf for BCA BBA.
The AUB Centre for AI in Media Proposal.docx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Review of recent advances in non-invasive hemoglobin estimation
Per capita expenditure prediction using model stacking based on satellite ima...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Machine learning based COVID-19 study performance prediction
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectroscopy.pptx food analysis technology
KodekX | Application Modernization Development
Spectral efficient network and resource selection model in 5G networks

On Functional Programming - A Clojurian Perspective