SlideShare a Scribd company logo
我把所有穿过的袜子在沙发上摆成一个二叉堆,每天回家便把袜子脱下来放在堆的最末尾,然后每次拿起两双袜子放在鼻子下闻闻,不断向上调整它在堆中的位置,直到比它的父亲更臭为止。这样,我每天早晨出门时便能方便地选出一双最不臭的袜子。
Clojure Practical Functional Approach on JVM Sun Ning 2011.11.28
Agenda Introduction to Clojure
Real World Clojure
Clojure People
 
Introduction to Clojure Functional Programming
Lisp Syntax
State Management
Macro
Java Interop
Introduction to Clojure Functional Programming
Lisp Syntax
State Management
Macro
Java Interop
Functional Programming Avoiding Mutable State
Functions as First-Class Values
Lambdas and Closures
Higher-Order Functions
Side-Effect-Free Functions
Recursion
Lazy vs. Eager Evaluation
Declarative vs. Imperative Programming
Functional Programming Avoiding Mutable State Better concurrency (no need for locking)
Persistent data structure zs = xs + ys
Functional Programming Functions as First-Class Values
Lambdas and Closures
Higher-Order Functions ;; integer as first class value (def a 10) ;; function as first class value (def b (fn [x] (+ x a))) ;; anonymous function #(+ a %) ;; function that generate a closure (def c (fn [x] #(+ x %))) ;; high order function (function as parameter) (def d (fn [f x] (f x a)))
Functional Programming Side-Effect-Free Functions ;; function that free of side effect (defn f [x] (+ x 1000)) ;; function with side effect (defn f [x] (println (str “logging: x=” x)) (+ x 1000)) ;; I/O operations are side effect (defn dump [writer data] (.write writer data))
Functional Programming Recursion Recursive Looping public int sumAll(int n) { int i = 1, s = 0; while(i <= n) { s = s + i; i++; } return s; } public int sumAll(int n) { if ( n > 0){ return n + sumAll(n-1); } else { return 0; } } (defn sum-all [n] (if (> n 0) (+ n (sum-all (dec n))) 0)) (defn sum-all2 [n s] (if (> n 0) ( recur  (dec n) (+ n s)) s)) (defn sum-all [n] (sum-all2 n 0)) java.lang.StackOverflowError Tail recursion
Functional Programming Lazy Evaluation ;; define data (def data [1 2 3 4 5]) ;; a function with side effect (defn side-effect-inc [i] (println i) (inc i)) ;; create lazy sequence with map (def lazy-data (map side-effect-inc data)) ;; consume first 2 items for lazy sequence (take 2 lazy-data) (1 2 3 4 5 2 3) (take 5 (range)) (take 5 (repeat “a”))
Functional Programming Declarative Programming DSL (cd &quot;/home/login&quot; (path &quot;/home/login/bin&quot; (run &quot;clojure&quot;))) (cd &quot;/home/login&quot; (path &quot;/home/login/bin&quot; (env &quot;JAVA_OPTS&quot; &quot;-XMaxPermSize=128m&quot; (run &quot;ant compile&quot;))))
Introduction to Clojure Functional Programming
Lisp Syntax
State Management
Macro
Java Interop
Syntax Symbol:  user/m
Character:  \a
Integer:  1 2 3
String:  “hello”
Keyword:  :world
Boolean:  true
Null:  nil
Collections Vector:  [1 2 3]
List:  (1 2 3)
Set:  #{1 2 3}

More Related Content

ZIP
Oral presentation v2
KEY
Alfresco the clojure way
PDF
Introduction to clojure
PPTX
iSoligorsk #3 2013
PDF
ES2015 (ES6) Overview
PDF
P6 OO vs Moose (&Moo)
PDF
Interceptors: Into the Core of Pedestal
PDF
Alfresco the clojure way -- Slides from the Alfresco DevCon2011
Oral presentation v2
Alfresco the clojure way
Introduction to clojure
iSoligorsk #3 2013
ES2015 (ES6) Overview
P6 OO vs Moose (&Moo)
Interceptors: Into the Core of Pedestal
Alfresco the clojure way -- Slides from the Alfresco DevCon2011

What's hot (20)

PDF
JRuby @ Boulder Ruby
PDF
ES6 in Production [JSConfUY2015]
KEY
Dispatch in Clojure
PDF
Oredev 2015 - Taming Java Agents
PDF
Clojurian Conquest
KEY
Mirah Talk for Boulder Ruby Group
PPT
Ggug spock
PDF
Effective ES6
PDF
ECMAScript 6
PDF
Explaining ES6: JavaScript History and What is to Come
PDF
Java Full Throttle
PDF
Swiftの関数型っぽい部分
PDF
Clojure and the Web
PPTX
Java 8 briefing
PDF
node ffi
PDF
JavaOne 2015 - Having fun with Javassist
PDF
Nick Sieger JRuby Concurrency EMRubyConf 2011
PDF
Shell script-sec
PDF
PHP7 is coming
PDF
GraphQL API in Clojure
JRuby @ Boulder Ruby
ES6 in Production [JSConfUY2015]
Dispatch in Clojure
Oredev 2015 - Taming Java Agents
Clojurian Conquest
Mirah Talk for Boulder Ruby Group
Ggug spock
Effective ES6
ECMAScript 6
Explaining ES6: JavaScript History and What is to Come
Java Full Throttle
Swiftの関数型っぽい部分
Clojure and the Web
Java 8 briefing
node ffi
JavaOne 2015 - Having fun with Javassist
Nick Sieger JRuby Concurrency EMRubyConf 2011
Shell script-sec
PHP7 is coming
GraphQL API in Clojure
Ad

Viewers also liked (18)

PDF
不自然なcar/ナチュラルにconsして
PDF
Writing Macros
PDF
Clojure Macros Workshop: LambdaJam 2013 / CUFP 2013
PDF
A Dive Into Clojure
PDF
Patterns
PPT
A little exercise with clojure macro
PDF
入門ClojureScript
PDF
Macros in Clojure
PDF
Continuation Passing Style and Macros in Clojure - Jan 2012
PPTX
Clojure的魅力
PPTX
Clojure概览
PDF
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
PDF
Clojureシンタックスハイライター開発から考えるこれからのlispに必要なもの
KEY
(map Clojure everyday-tasks)
KEY
PDF
DSL in Clojure
PDF
プログラミング言語Clojureのニャンパスでの活用事例
PDF
Clojure from ground up
不自然なcar/ナチュラルにconsして
Writing Macros
Clojure Macros Workshop: LambdaJam 2013 / CUFP 2013
A Dive Into Clojure
Patterns
A little exercise with clojure macro
入門ClojureScript
Macros in Clojure
Continuation Passing Style and Macros in Clojure - Jan 2012
Clojure的魅力
Clojure概览
Stefan Richter - Writing simple, readable and robust code: Examples in Java, ...
Clojureシンタックスハイライター開発から考えるこれからのlispに必要なもの
(map Clojure everyday-tasks)
DSL in Clojure
プログラミング言語Clojureのニャンパスでの活用事例
Clojure from ground up
Ad

Similar to Clojure: Practical functional approach on JVM (20)

PDF
Pune Clojure Course Outline
KEY
Clojure Intro
PDF
Thinking Functionally with Clojure
PDF
Thinking Functionally - John Stevenson - Codemotion Rome 2017
PPTX
Clojure 7-Languages
PDF
Get into Functional Programming with Clojure
PDF
Fun with Functional Programming in Clojure
PDF
On Functional Programming - A Clojurian Perspective
PDF
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
PDF
Clojure
PDF
PDF
Clojure - A new Lisp
PDF
Full Stack Clojure
PDF
(first '(Clojure.))
PDF
Clojure: Simple By Design
ODP
Clojure basics
PDF
Functional Programming with Clojure
PPT
PDF
Functional web with clojure
PDF
Get Functional Programming with Clojure
Pune Clojure Course Outline
Clojure Intro
Thinking Functionally with Clojure
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Clojure 7-Languages
Get into Functional Programming with Clojure
Fun with Functional Programming in Clojure
On Functional Programming - A Clojurian Perspective
Fun with Functional Programming in Clojure - John Stevenson - Codemotion Amst...
Clojure
Clojure - A new Lisp
Full Stack Clojure
(first '(Clojure.))
Clojure: Simple By Design
Clojure basics
Functional Programming with Clojure
Functional web with clojure
Get Functional Programming with Clojure

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Approach and Philosophy of On baking technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Electronic commerce courselecture one. Pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPT
Teaching material agriculture food technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
MYSQL Presentation for SQL database connectivity
Encapsulation theory and applications.pdf
NewMind AI Monthly Chronicles - July 2025
Approach and Philosophy of On baking technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Review of recent advances in non-invasive hemoglobin estimation
Spectral efficient network and resource selection model in 5G networks
Dropbox Q2 2025 Financial Results & Investor Presentation
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Electronic commerce courselecture one. Pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Machine learning based COVID-19 study performance prediction
Understanding_Digital_Forensics_Presentation.pptx
Teaching material agriculture food technology
Chapter 3 Spatial Domain Image Processing.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
MYSQL Presentation for SQL database connectivity

Clojure: Practical functional approach on JVM