SlideShare a Scribd company logo
1 of 42
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

What's hot

Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.
Mike Fogus
 
Opa presentation at GamesJs
Opa presentation at GamesJsOpa presentation at GamesJs
Opa presentation at GamesJs
Henri Binsztok
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 

What's hot (19)

Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.
 
Opa presentation at GamesJs
Opa presentation at GamesJsOpa presentation at GamesJs
Opa presentation at GamesJs
 
Android Guava
Android GuavaAndroid Guava
Android Guava
 
Javascript development done right
Javascript development done rightJavascript development done right
Javascript development done right
 
Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
 
The Macronomicon
The MacronomiconThe Macronomicon
The Macronomicon
 
Linq introduction
Linq introductionLinq introduction
Linq introduction
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
 
Clojure入門
Clojure入門Clojure入門
Clojure入門
 
Rakudo
RakudoRakudo
Rakudo
 
String functions
String functionsString functions
String functions
 
C# 7
C# 7C# 7
C# 7
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Fun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming languageFun never stops. introduction to haskell programming language
Fun never stops. introduction to haskell programming language
 
Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and Reactive
 
Intro to F#
Intro to F#Intro to F#
Intro to F#
 
Haskell
HaskellHaskell
Haskell
 

Viewers also liked (6)

für dilay
für dilayfür dilay
für dilay
 
WordCamp Romania 2010 - mobile web si WordPress
WordCamp Romania 2010 - mobile web si WordPressWordCamp Romania 2010 - mobile web si WordPress
WordCamp Romania 2010 - mobile web si WordPress
 
Web Analytics
Web AnalyticsWeb Analytics
Web Analytics
 
Fran Mancia Use/Creation JPAs
Fran Mancia Use/Creation JPAsFran Mancia Use/Creation JPAs
Fran Mancia Use/Creation JPAs
 
Brochure
BrochureBrochure
Brochure
 
Ky Nang Giao Quyen
Ky Nang Giao QuyenKy Nang Giao Quyen
Ky Nang Giao Quyen
 

Similar to On Functional Programming - A Clojurian Perspective

Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
Jan Kronquist
 
Pragmatic Real-World Scala
Pragmatic Real-World ScalaPragmatic Real-World Scala
Pragmatic Real-World Scala
parag978978
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
Predictably
PredictablyPredictably
Predictably
ztellman
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
Ross Lawley
 

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

Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Pragmatic Real-World Scala
Pragmatic Real-World ScalaPragmatic Real-World Scala
Pragmatic Real-World Scala
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
From Javascript To Haskell
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskell
 
Groovy
GroovyGroovy
Groovy
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
From Java To Clojure (English version)
From Java To Clojure (English version)From Java To Clojure (English version)
From Java To Clojure (English version)
 
Predictably
PredictablyPredictably
Predictably
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talk
 
(first '(Clojure.))
(first '(Clojure.))(first '(Clojure.))
(first '(Clojure.))
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
 
Groovy.pptx
Groovy.pptxGroovy.pptx
Groovy.pptx
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVM
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
JavaScript @ CTK
JavaScript @ CTKJavaScript @ CTK
JavaScript @ CTK
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
 
FunctionalJS - George Shevtsov
FunctionalJS - George ShevtsovFunctionalJS - George Shevtsov
FunctionalJS - George Shevtsov
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

On Functional Programming - A Clojurian Perspective