SlideShare a Scribd company logo
1 of 15
Clojure
● LISP on the JVM
● Dynamic
● Started in 2007 by Rich Hickey
● 3 years of planning
● Current version - 1.6.0
● Eclipse license
Defining Features
● LISP syntax but not Common LISP or Scheme
– Macros
● Immutability
● Functional
● JVM based
– Java interop
– Not OOP
● Supports Concurrency
Syntax
● Numbers: 1234, 1.234, 1.234M
● Ratios: 22/7
● Strings: “foo”, “bar”, Characters: a b c
● Symbols: foo, bar, Keywords: :foo, :bar
● Boolean: true, false, Null: nil
● Regex Patterns: #”a*b”
Data Structures
● Lists – singly linked, grow at front:
– (1 2 3 4)
● Vectors – indexed, grow at end:
– [1 2 3 4]
● Maps – key/value associations:
– {:a 1 :b 2 :c 3}
● Sets: #{:a :b :c}
● Everything nests inside each other
Syntax
● That's the entire syntax
● Data strcuture are the code (Homoiconicity)
● All data literals stand for themselves except:
– Lists (IFn invocation)
– Symbols (“pointers”)
Lists as Invocations Example
● (+ 1 1) => 2
● (+ 1 2 (+ 3 4 5)) => 15
● (first [:a :b :c]) => :a
● (rest [:a :b :c]) => (:b :c)
● (class “foo”) => java.lang.String
● (class 1) => java.long.Long
Persistent Data Structures
● All Clojure data structures are persistent
● Collections maintain performance guarantees:
– New + Old version of collections are available after
change
– New versions are not full copies
– Thread safe, iteration safe
● Sequences replace traditional lists
– All Clojure and Java collections can be made into
seqs
Persistent Data Structure
Performance
● O(log32 N) ~= O(1)
A
B C
D E F G
H I J K L M N'
A’
C’
G’
N
Seq General Macros
● All seqs, which means all lists, vectors, hash-
maps, hash-sets, strings etc. can use the multi
purpose seq macros. A kind of polymorphism
over collections.
(def xs [:a :b :c])
– (first xs) => :a , (rest xs) => (:b :c)
– (count xs) => 3 , (contains? xs :d) => false
– (remove #(= % :b) xs) => (:a :c)
– (nth xs 2) => :c
Laziness
● Seqs can be lazy
– (repeat :a) => (:a :a :a :a :a …)
● Processing is delayed until the seq is realized:
– (class (repeat :a)) => clojure.lang.LazySeq
● Realize part of a lazy seq:
– (take 3 (repeat :a)) => (:a :a :a)
Philosophy
● Use libraries instead of frameworks
● REPL first development
– Small and isolated functions
● Data structures instead of classes
DEMO
Java Interop
● (.toLowerCase “AppsFlyer”) => “appsflyer”
– (.<method> <object> [<arg1> …])
● (Foo. “bar”) => #<Foo bar>
– (<class>. [<constrcutor arg1>...])
● (Integer/parseInt “5”) => 5
– (<class>/<static method> [<arg1>...])
● (.contains “AppsFlyer FTW” “FTW”) => true
Concurrency
● Clojure uses STM – no locks in the code
– Multiversion Concurrency Control (MVCC)
– Readers never impede writers and writers never impeded
readers
● 3 primitive containers to store mutable data – atom,
ref, agent
– Refs – coordinated-sync access to many identities
– Atoms – Uncoordinated-sync access to a single identity
– Agents – Uncoordinated-async access to a single identity
So Much More...
● Metadata
● Optimized tail recursion
● Destructuring binding in let/fn/loop
● List comprehensions
● Multimethods
● Parallel computations
● Macros

More Related Content

What's hot

Simplifying development-short - Mirco Dotta (Typesafe)
Simplifying development-short - Mirco Dotta (Typesafe)Simplifying development-short - Mirco Dotta (Typesafe)
Simplifying development-short - Mirco Dotta (Typesafe)Scala Italy
 
Frontend application architecture, patterns, and workflows
Frontend application architecture, patterns, and workflowsFrontend application architecture, patterns, and workflows
Frontend application architecture, patterns, and workflowsCesar Andreu
 
Coding convention
Coding conventionCoding convention
Coding conventionKhoa Nguyen
 
ConvNetJS & CaffeJS
ConvNetJS & CaffeJSConvNetJS & CaffeJS
ConvNetJS & CaffeJSAnyline
 
Java JVM Memory Cheat Sheet
Java JVM Memory Cheat SheetJava JVM Memory Cheat Sheet
Java JVM Memory Cheat SheetMark Papis
 
Dax Declarative Api For Xml
Dax   Declarative Api For XmlDax   Declarative Api For Xml
Dax Declarative Api For XmlLars Trieloff
 

What's hot (8)

Simplifying development-short - Mirco Dotta (Typesafe)
Simplifying development-short - Mirco Dotta (Typesafe)Simplifying development-short - Mirco Dotta (Typesafe)
Simplifying development-short - Mirco Dotta (Typesafe)
 
Meet the-other-elephant
Meet the-other-elephantMeet the-other-elephant
Meet the-other-elephant
 
Frontend application architecture, patterns, and workflows
Frontend application architecture, patterns, and workflowsFrontend application architecture, patterns, and workflows
Frontend application architecture, patterns, and workflows
 
Towards hasktorch 1.0
Towards hasktorch 1.0Towards hasktorch 1.0
Towards hasktorch 1.0
 
Coding convention
Coding conventionCoding convention
Coding convention
 
ConvNetJS & CaffeJS
ConvNetJS & CaffeJSConvNetJS & CaffeJS
ConvNetJS & CaffeJS
 
Java JVM Memory Cheat Sheet
Java JVM Memory Cheat SheetJava JVM Memory Cheat Sheet
Java JVM Memory Cheat Sheet
 
Dax Declarative Api For Xml
Dax   Declarative Api For XmlDax   Declarative Api For Xml
Dax Declarative Api For Xml
 

Similar to Clojure presentation

Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmerselliando dias
 
Design and Implementation of the Security Graph Language
Design and Implementation of the Security Graph LanguageDesign and Implementation of the Security Graph Language
Design and Implementation of the Security Graph LanguageAsankhaya Sharma
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumNgoc Dao
 
Thorny Path to the Large Scale Graph Processing, Алексей Зиновьев (Тамтэк)
Thorny Path to the Large Scale Graph Processing, Алексей Зиновьев (Тамтэк)Thorny Path to the Large Scale Graph Processing, Алексей Зиновьев (Тамтэк)
Thorny Path to the Large Scale Graph Processing, Алексей Зиновьев (Тамтэк)Ontico
 
Thorny path to the Large-Scale Graph Processing (Highload++, 2014)
Thorny path to the Large-Scale Graph Processing (Highload++, 2014)Thorny path to the Large-Scale Graph Processing (Highload++, 2014)
Thorny path to the Large-Scale Graph Processing (Highload++, 2014)Alexey Zinoviev
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsMiles Sabin
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp languageDavid Gu
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011Patrick Walton
 
From Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn IntroductionFrom Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn Introductionelliando dias
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play frameworkFelipe
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the webMichiel Borkent
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.Ruslan Shevchenko
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxSam Bowne
 

Similar to Clojure presentation (20)

Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmers
 
Design and Implementation of the Security Graph Language
Design and Implementation of the Security Graph LanguageDesign and Implementation of the Security Graph Language
Design and Implementation of the Security Graph Language
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Thorny Path to the Large Scale Graph Processing, Алексей Зиновьев (Тамтэк)
Thorny Path to the Large Scale Graph Processing, Алексей Зиновьев (Тамтэк)Thorny Path to the Large Scale Graph Processing, Алексей Зиновьев (Тамтэк)
Thorny Path to the Large Scale Graph Processing, Алексей Зиновьев (Тамтэк)
 
Thorny path to the Large-Scale Graph Processing (Highload++, 2014)
Thorny path to the Large-Scale Graph Processing (Highload++, 2014)Thorny path to the Large-Scale Graph Processing (Highload++, 2014)
Thorny path to the Large-Scale Graph Processing (Highload++, 2014)
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
 
A brief introduction to lisp language
A brief introduction to lisp languageA brief introduction to lisp language
A brief introduction to lisp language
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011
 
MATLAB Programming
MATLAB Programming MATLAB Programming
MATLAB Programming
 
R programmingmilano
R programmingmilanoR programmingmilano
R programmingmilano
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
From Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn IntroductionFrom Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn Introduction
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
 
Java 8
Java 8Java 8
Java 8
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play framework
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
HPC Essentials 0
HPC Essentials 0HPC Essentials 0
HPC Essentials 0
 
ClojureScript for the web
ClojureScript for the webClojureScript for the web
ClojureScript for the web
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
 

More from Tikal Knowledge

Tabtale story: Building a publishing and monitoring mobile games architecture...
Tabtale story: Building a publishing and monitoring mobile games architecture...Tabtale story: Building a publishing and monitoring mobile games architecture...
Tabtale story: Building a publishing and monitoring mobile games architecture...Tikal Knowledge
 
Processing Big Data in Realtime
Processing Big Data in RealtimeProcessing Big Data in Realtime
Processing Big Data in RealtimeTikal Knowledge
 
Docking your services_with_docker
Docking your services_with_dockerDocking your services_with_docker
Docking your services_with_dockerTikal Knowledge
 
Writing a Fullstack Application with Javascript - Remote media player
Writing a Fullstack Application with Javascript - Remote media playerWriting a Fullstack Application with Javascript - Remote media player
Writing a Fullstack Application with Javascript - Remote media playerTikal Knowledge
 
.Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013
.Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013 .Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013
.Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013 Tikal Knowledge
 
Tikal's Backbone_js introduction workshop
Tikal's Backbone_js introduction workshopTikal's Backbone_js introduction workshop
Tikal's Backbone_js introduction workshopTikal Knowledge
 
Cloud computing - an insight into "how does it really work ?"
Cloud computing - an insight into "how does it really work ?" Cloud computing - an insight into "how does it really work ?"
Cloud computing - an insight into "how does it really work ?" Tikal Knowledge
 
Introduction to Cloud Computing
Introduction to Cloud ComputingIntroduction to Cloud Computing
Introduction to Cloud ComputingTikal Knowledge
 
Tikal Fuse Day Access Layer Implementation (C#) Based On Mongo Db
Tikal Fuse Day   Access Layer Implementation (C#) Based On Mongo DbTikal Fuse Day   Access Layer Implementation (C#) Based On Mongo Db
Tikal Fuse Day Access Layer Implementation (C#) Based On Mongo DbTikal Knowledge
 
Ship early ship often with Django
Ship early ship often with DjangoShip early ship often with Django
Ship early ship often with DjangoTikal Knowledge
 
Introduction To Cloud Computing
Introduction To Cloud ComputingIntroduction To Cloud Computing
Introduction To Cloud ComputingTikal Knowledge
 
Building Components In Flex3
Building Components In Flex3Building Components In Flex3
Building Components In Flex3Tikal Knowledge
 

More from Tikal Knowledge (20)

Tabtale story: Building a publishing and monitoring mobile games architecture...
Tabtale story: Building a publishing and monitoring mobile games architecture...Tabtale story: Building a publishing and monitoring mobile games architecture...
Tabtale story: Building a publishing and monitoring mobile games architecture...
 
Kafka short
Kafka shortKafka short
Kafka short
 
Heatmap
HeatmapHeatmap
Heatmap
 
Processing Big Data in Realtime
Processing Big Data in RealtimeProcessing Big Data in Realtime
Processing Big Data in Realtime
 
Docking your services_with_docker
Docking your services_with_dockerDocking your services_with_docker
Docking your services_with_docker
 
Who moved my_box
Who moved my_boxWho moved my_box
Who moved my_box
 
Writing a Fullstack Application with Javascript - Remote media player
Writing a Fullstack Application with Javascript - Remote media playerWriting a Fullstack Application with Javascript - Remote media player
Writing a Fullstack Application with Javascript - Remote media player
 
.Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013
.Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013 .Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013
.Net OSS Ci & CD with Jenkins - JUC ISRAEL 2013
 
Tikal's Backbone_js introduction workshop
Tikal's Backbone_js introduction workshopTikal's Backbone_js introduction workshop
Tikal's Backbone_js introduction workshop
 
TCE Automation
TCE AutomationTCE Automation
TCE Automation
 
Tce automation-d4
Tce automation-d4Tce automation-d4
Tce automation-d4
 
Cloud computing - an insight into "how does it really work ?"
Cloud computing - an insight into "how does it really work ?" Cloud computing - an insight into "how does it really work ?"
Cloud computing - an insight into "how does it really work ?"
 
Introduction to Cloud Computing
Introduction to Cloud ComputingIntroduction to Cloud Computing
Introduction to Cloud Computing
 
Tikal Fuse Day Access Layer Implementation (C#) Based On Mongo Db
Tikal Fuse Day   Access Layer Implementation (C#) Based On Mongo DbTikal Fuse Day   Access Layer Implementation (C#) Based On Mongo Db
Tikal Fuse Day Access Layer Implementation (C#) Based On Mongo Db
 
Ship early ship often with Django
Ship early ship often with DjangoShip early ship often with Django
Ship early ship often with Django
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
AWS Case Study
AWS Case StudyAWS Case Study
AWS Case Study
 
Introduction To Cloud Computing
Introduction To Cloud ComputingIntroduction To Cloud Computing
Introduction To Cloud Computing
 
Building Components In Flex3
Building Components In Flex3Building Components In Flex3
Building Components In Flex3
 
Osgi Democamp
Osgi DemocampOsgi Democamp
Osgi Democamp
 

Clojure presentation

  • 1. Clojure ● LISP on the JVM ● Dynamic ● Started in 2007 by Rich Hickey ● 3 years of planning ● Current version - 1.6.0 ● Eclipse license
  • 2. Defining Features ● LISP syntax but not Common LISP or Scheme – Macros ● Immutability ● Functional ● JVM based – Java interop – Not OOP ● Supports Concurrency
  • 3. Syntax ● Numbers: 1234, 1.234, 1.234M ● Ratios: 22/7 ● Strings: “foo”, “bar”, Characters: a b c ● Symbols: foo, bar, Keywords: :foo, :bar ● Boolean: true, false, Null: nil ● Regex Patterns: #”a*b”
  • 4. Data Structures ● Lists – singly linked, grow at front: – (1 2 3 4) ● Vectors – indexed, grow at end: – [1 2 3 4] ● Maps – key/value associations: – {:a 1 :b 2 :c 3} ● Sets: #{:a :b :c} ● Everything nests inside each other
  • 5. Syntax ● That's the entire syntax ● Data strcuture are the code (Homoiconicity) ● All data literals stand for themselves except: – Lists (IFn invocation) – Symbols (“pointers”)
  • 6. Lists as Invocations Example ● (+ 1 1) => 2 ● (+ 1 2 (+ 3 4 5)) => 15 ● (first [:a :b :c]) => :a ● (rest [:a :b :c]) => (:b :c) ● (class “foo”) => java.lang.String ● (class 1) => java.long.Long
  • 7. Persistent Data Structures ● All Clojure data structures are persistent ● Collections maintain performance guarantees: – New + Old version of collections are available after change – New versions are not full copies – Thread safe, iteration safe ● Sequences replace traditional lists – All Clojure and Java collections can be made into seqs
  • 8. Persistent Data Structure Performance ● O(log32 N) ~= O(1) A B C D E F G H I J K L M N' A’ C’ G’ N
  • 9. Seq General Macros ● All seqs, which means all lists, vectors, hash- maps, hash-sets, strings etc. can use the multi purpose seq macros. A kind of polymorphism over collections. (def xs [:a :b :c]) – (first xs) => :a , (rest xs) => (:b :c) – (count xs) => 3 , (contains? xs :d) => false – (remove #(= % :b) xs) => (:a :c) – (nth xs 2) => :c
  • 10. Laziness ● Seqs can be lazy – (repeat :a) => (:a :a :a :a :a …) ● Processing is delayed until the seq is realized: – (class (repeat :a)) => clojure.lang.LazySeq ● Realize part of a lazy seq: – (take 3 (repeat :a)) => (:a :a :a)
  • 11. Philosophy ● Use libraries instead of frameworks ● REPL first development – Small and isolated functions ● Data structures instead of classes
  • 12. DEMO
  • 13. Java Interop ● (.toLowerCase “AppsFlyer”) => “appsflyer” – (.<method> <object> [<arg1> …]) ● (Foo. “bar”) => #<Foo bar> – (<class>. [<constrcutor arg1>...]) ● (Integer/parseInt “5”) => 5 – (<class>/<static method> [<arg1>...]) ● (.contains “AppsFlyer FTW” “FTW”) => true
  • 14. Concurrency ● Clojure uses STM – no locks in the code – Multiversion Concurrency Control (MVCC) – Readers never impede writers and writers never impeded readers ● 3 primitive containers to store mutable data – atom, ref, agent – Refs – coordinated-sync access to many identities – Atoms – Uncoordinated-sync access to a single identity – Agents – Uncoordinated-async access to a single identity
  • 15. So Much More... ● Metadata ● Optimized tail recursion ● Destructuring binding in let/fn/loop ● List comprehensions ● Multimethods ● Parallel computations ● Macros