SlideShare a Scribd company logo
Functional Programming on the JVM
           using Clojure

         Baishampayan Ghose
          Infinitely Beta Technologies


             GNUnify 2010




                                        1 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    2 / 31
Who am I?



  My name is BG and I am a Computer guy
     FP head
     Scale nerd
     Prog-lang lawyer
     Web standards ninja
  FOSS geek
  Startup-ist




                                          3 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    4 / 31
What, why and how of Clojure




   What is Clojure?
   Why a new programming language?
   How is Clojure any better than X?




                                       5 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    6 / 31
Fundamentals



  Clojure is a Lisp
  Clojure is dynamic
  Clojure is hosted on the JVM
  Clojure is functional
  Clojure is geared towards concurrency
  Free & Open Source




                                          7 / 31
Integers — 1234567891234
Doubles — 3.14, BigDecimals — 1.23M
Ratios — 22/4
Strings — “foo”, Characters — a b c
Symbols — foo bar, Keyword — :foo :bar
Booleans — true false, Null — nil
Regex patterns — #“[a-zA-Z0-9]”




                                         8 / 31
Data Structures


   Lists
       (1 2 3 4 5), (foo bar baz), (list 1 2 3)
   Vectors
       [1 2 3 4 5], [foo bar baz], (vector 1 2 3)
   Maps
       {:a 1 :b 2 :c 3}, (hash-map :x 1 :y 2)
   Sets
       #{foo bar baz}




                                                    9 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    10 / 31
Syntax


  There is no other syntax!
  Data structures are the code
  No other text based syntax, just different
  interpretations
  There is a fancy name for this — Homoiconicity




                                                   11 / 31
Syntax


  There is no other syntax!
  Data structures are the code
  No other text based syntax, just different
  interpretations
  There is a fancy name for this — Homoiconicity
  Everything is an expression
  All data literals stand for themselves, except —
     Symbols
     Lists




                                                     11 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    12 / 31
Hello, Clojure!


hello.clj
(ns hello)

(defn hello
    "Say hello to name"
    [name]
    (str "Hello, " name "!"))

(hello "Clojure") ; -> "Hello, Clojure!"




                                           13 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    14 / 31
Sequences


  An abstraction over traditional Lisp lists
  Provides an uniform way of walking through data
  structures
  (seq coll)
     If collection is non-empty, return a sequence object
  (first s)
     Return the first item
  (rest s)
     Return a seq of the rest of elements




                                                       15 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    16 / 31
Java Inter-op


   Wrapper free interface to Java
   Syntactic sugar to make Java invocation easy
   Core Clojure abstractions are Java interfaces
   Clojure functions implement Callable & Runnable
   Clojure sequence library works on Java iterables
   Easy to implement, extend Java interfaces (if
   needed)
   Almost identical to Java in terms of speed




                                                      17 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    18 / 31
Concurrency


  Simultaneous execution
  Avoid reading,yielding inconsistent data




                                             19 / 31
Concurrency


  Simultaneous execution
  Avoid reading,yielding inconsistent data

              Synchronous           Asynchronous
  Coordinated      ref
  Independent     atom                   agent
  Unshared         var
     Table: Building blocks of Clojure concurrency




                                                     19 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    20 / 31
Multimethods



  Generalised indirect dispatch
  Dispatch on a arbitrary function of the arguments




                                                      21 / 31
Multimethods



  Generalised indirect dispatch
  Dispatch on a arbitrary function of the arguments
  Call sequence
     Call dispatch function on args to get dispatch value
     Find method associated with dispatch value




                                                       21 / 31
Multimethods



  Generalised indirect dispatch
  Dispatch on a arbitrary function of the arguments
  Call sequence
     Call dispatch function on args to get dispatch value
     Find method associated with dispatch value
         Else call default method, else error




                                                       21 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    22 / 31
There is more!


   Metadata
   Destructuring
   Transients
   Zippers
   Futures, Promises
   clojure.contrib

          Ping me after the talk for details




                                               23 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    24 / 31
Tools



   Emacs + SLIME + paredit
   ViMClojure
   Enclojure + IntelliJ IDEA
   Counterclockwise + Eclipse
   Leiningen




                                25 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    26 / 31
Resources



  Programming Clojure by Stuart Halloway
  http://en.wikibooks.org/wiki/Clojure
  http://clojure.org
  http://groups.google.com/group/clojure
  http://planet.clojure.in
  http://clojure.blip.tv




                                           27 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    28 / 31
Questions?




             29 / 31
Outline
1    Who am I?
2    What, why and how of Clojure
3    Fundamentals
4    Syntax
5    Hello, Clojure!
6    Sequences
7    Java Inter-op
8    Concurrency
9    Multimethods
10   There is more!
11   Tools
12   Resources
13   Q&A
14   Contacting me
                                    30 / 31
Contacting me

   http://freegeek.in/
   bg@infinitelybeta.com
   @ghoseb on Twitter
   Slides on - http://bit.ly/gnunify-clojure

  Infinitely Beta is recruiting smart hackers!
         http://infinitelybeta.com/jobs/




                    CC BY SA


                                                31 / 31

More Related Content

Similar to Introduction to Clojure

Introductory Clojure Presentation
Introductory Clojure PresentationIntroductory Clojure Presentation
Introductory Clojure Presentation
Jay Victoria
 
Clojure
ClojureClojure
Clojure
alandipert
 
I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?
sbjug
 
Philipp Von Weitershausen Plone Age Mammoths, Sabers And Caveen Cant The...
Philipp Von Weitershausen   Plone Age  Mammoths, Sabers And Caveen   Cant The...Philipp Von Weitershausen   Plone Age  Mammoths, Sabers And Caveen   Cant The...
Philipp Von Weitershausen Plone Age Mammoths, Sabers And Caveen Cant The...
Vincenzo Barone
 
Programming with Freedom & Joy
Programming with Freedom & JoyProgramming with Freedom & Joy
Programming with Freedom & Joy
Hildeberto Mendonça
 
Clojure and The Robot Apocalypse
Clojure and The Robot ApocalypseClojure and The Robot Apocalypse
Clojure and The Robot Apocalypseelliando dias
 
Why Functional Programming and Clojure - LightningTalk
Why Functional Programming and Clojure - LightningTalkWhy Functional Programming and Clojure - LightningTalk
Why Functional Programming and Clojure - LightningTalk
Jakub Holy
 
Neo4j - 7 databases in 7 weeks
Neo4j - 7 databases in 7 weeksNeo4j - 7 databases in 7 weeks
Neo4j - 7 databases in 7 weeks
Landier Nicolas
 
Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...
Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...
Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...
Codemotion
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJAX London
 
Seeking Clojure
Seeking ClojureSeeking Clojure
Seeking Clojure
chrisriceuk
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java Developers
Kostas Saidis
 
Clojure Small Intro
Clojure Small IntroClojure Small Intro
Clojure Small Intro
John Vlachoyiannis
 
Multithreading in Scala
Multithreading in Scala Multithreading in Scala
Multithreading in Scala
Knoldus Inc.
 
Clojure - A practical LISP for the JVM
Clojure - A practical LISP for the JVMClojure - A practical LISP for the JVM
Clojure - A practical LISP for the JVM
Matthias Nüßler
 
TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...
TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...
TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...
tdc-globalcode
 
Cats And Dogs Living Together: Langsec Is Also About Usability
Cats And Dogs Living Together: Langsec Is Also About UsabilityCats And Dogs Living Together: Langsec Is Also About Usability
Cats And Dogs Living Together: Langsec Is Also About Usability
Meredith Patterson
 
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemApache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystem
Kostas Saidis
 
The *on-going* future of Perl5
The *on-going* future of Perl5The *on-going* future of Perl5
The *on-going* future of Perl5
Vytautas Dauksa
 
Modeling with petri nets
Modeling with petri netsModeling with petri nets
Modeling with petri nets
Mohammed Assiri
 

Similar to Introduction to Clojure (20)

Introductory Clojure Presentation
Introductory Clojure PresentationIntroductory Clojure Presentation
Introductory Clojure Presentation
 
Clojure
ClojureClojure
Clojure
 
I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?
 
Philipp Von Weitershausen Plone Age Mammoths, Sabers And Caveen Cant The...
Philipp Von Weitershausen   Plone Age  Mammoths, Sabers And Caveen   Cant The...Philipp Von Weitershausen   Plone Age  Mammoths, Sabers And Caveen   Cant The...
Philipp Von Weitershausen Plone Age Mammoths, Sabers And Caveen Cant The...
 
Programming with Freedom & Joy
Programming with Freedom & JoyProgramming with Freedom & Joy
Programming with Freedom & Joy
 
Clojure and The Robot Apocalypse
Clojure and The Robot ApocalypseClojure and The Robot Apocalypse
Clojure and The Robot Apocalypse
 
Why Functional Programming and Clojure - LightningTalk
Why Functional Programming and Clojure - LightningTalkWhy Functional Programming and Clojure - LightningTalk
Why Functional Programming and Clojure - LightningTalk
 
Neo4j - 7 databases in 7 weeks
Neo4j - 7 databases in 7 weeksNeo4j - 7 databases in 7 weeks
Neo4j - 7 databases in 7 weeks
 
Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...
Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...
Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
 
Seeking Clojure
Seeking ClojureSeeking Clojure
Seeking Clojure
 
An Introduction to Groovy for Java Developers
An Introduction to Groovy for Java DevelopersAn Introduction to Groovy for Java Developers
An Introduction to Groovy for Java Developers
 
Clojure Small Intro
Clojure Small IntroClojure Small Intro
Clojure Small Intro
 
Multithreading in Scala
Multithreading in Scala Multithreading in Scala
Multithreading in Scala
 
Clojure - A practical LISP for the JVM
Clojure - A practical LISP for the JVMClojure - A practical LISP for the JVM
Clojure - A practical LISP for the JVM
 
TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...
TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...
TDC2016POA | Trilha Programacao Funcional - Considere usar Clojure/ClojureScr...
 
Cats And Dogs Living Together: Langsec Is Also About Usability
Cats And Dogs Living Together: Langsec Is Also About UsabilityCats And Dogs Living Together: Langsec Is Also About Usability
Cats And Dogs Living Together: Langsec Is Also About Usability
 
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemApache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystem
 
The *on-going* future of Perl5
The *on-going* future of Perl5The *on-going* future of Perl5
The *on-going* future of Perl5
 
Modeling with petri nets
Modeling with petri netsModeling with petri nets
Modeling with petri nets
 

Recently uploaded

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 

Recently uploaded (20)

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 

Introduction to Clojure

  • 1. Functional Programming on the JVM using Clojure Baishampayan Ghose Infinitely Beta Technologies GNUnify 2010 1 / 31
  • 2. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 2 / 31
  • 3. Who am I? My name is BG and I am a Computer guy FP head Scale nerd Prog-lang lawyer Web standards ninja FOSS geek Startup-ist 3 / 31
  • 4. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 4 / 31
  • 5. What, why and how of Clojure What is Clojure? Why a new programming language? How is Clojure any better than X? 5 / 31
  • 6. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 6 / 31
  • 7. Fundamentals Clojure is a Lisp Clojure is dynamic Clojure is hosted on the JVM Clojure is functional Clojure is geared towards concurrency Free & Open Source 7 / 31
  • 8. Integers — 1234567891234 Doubles — 3.14, BigDecimals — 1.23M Ratios — 22/4 Strings — “foo”, Characters — a b c Symbols — foo bar, Keyword — :foo :bar Booleans — true false, Null — nil Regex patterns — #“[a-zA-Z0-9]” 8 / 31
  • 9. Data Structures Lists (1 2 3 4 5), (foo bar baz), (list 1 2 3) Vectors [1 2 3 4 5], [foo bar baz], (vector 1 2 3) Maps {:a 1 :b 2 :c 3}, (hash-map :x 1 :y 2) Sets #{foo bar baz} 9 / 31
  • 10. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 10 / 31
  • 11. Syntax There is no other syntax! Data structures are the code No other text based syntax, just different interpretations There is a fancy name for this — Homoiconicity 11 / 31
  • 12. Syntax There is no other syntax! Data structures are the code No other text based syntax, just different interpretations There is a fancy name for this — Homoiconicity Everything is an expression All data literals stand for themselves, except — Symbols Lists 11 / 31
  • 13. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 12 / 31
  • 14. Hello, Clojure! hello.clj (ns hello) (defn hello "Say hello to name" [name] (str "Hello, " name "!")) (hello "Clojure") ; -> "Hello, Clojure!" 13 / 31
  • 15. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 14 / 31
  • 16. Sequences An abstraction over traditional Lisp lists Provides an uniform way of walking through data structures (seq coll) If collection is non-empty, return a sequence object (first s) Return the first item (rest s) Return a seq of the rest of elements 15 / 31
  • 17. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 16 / 31
  • 18. Java Inter-op Wrapper free interface to Java Syntactic sugar to make Java invocation easy Core Clojure abstractions are Java interfaces Clojure functions implement Callable & Runnable Clojure sequence library works on Java iterables Easy to implement, extend Java interfaces (if needed) Almost identical to Java in terms of speed 17 / 31
  • 19. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 18 / 31
  • 20. Concurrency Simultaneous execution Avoid reading,yielding inconsistent data 19 / 31
  • 21. Concurrency Simultaneous execution Avoid reading,yielding inconsistent data Synchronous Asynchronous Coordinated ref Independent atom agent Unshared var Table: Building blocks of Clojure concurrency 19 / 31
  • 22. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 20 / 31
  • 23. Multimethods Generalised indirect dispatch Dispatch on a arbitrary function of the arguments 21 / 31
  • 24. Multimethods Generalised indirect dispatch Dispatch on a arbitrary function of the arguments Call sequence Call dispatch function on args to get dispatch value Find method associated with dispatch value 21 / 31
  • 25. Multimethods Generalised indirect dispatch Dispatch on a arbitrary function of the arguments Call sequence Call dispatch function on args to get dispatch value Find method associated with dispatch value Else call default method, else error 21 / 31
  • 26. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 22 / 31
  • 27. There is more! Metadata Destructuring Transients Zippers Futures, Promises clojure.contrib Ping me after the talk for details 23 / 31
  • 28. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 24 / 31
  • 29. Tools Emacs + SLIME + paredit ViMClojure Enclojure + IntelliJ IDEA Counterclockwise + Eclipse Leiningen 25 / 31
  • 30. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 26 / 31
  • 31. Resources Programming Clojure by Stuart Halloway http://en.wikibooks.org/wiki/Clojure http://clojure.org http://groups.google.com/group/clojure http://planet.clojure.in http://clojure.blip.tv 27 / 31
  • 32. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 28 / 31
  • 33. Questions? 29 / 31
  • 34. Outline 1 Who am I? 2 What, why and how of Clojure 3 Fundamentals 4 Syntax 5 Hello, Clojure! 6 Sequences 7 Java Inter-op 8 Concurrency 9 Multimethods 10 There is more! 11 Tools 12 Resources 13 Q&A 14 Contacting me 30 / 31
  • 35. Contacting me http://freegeek.in/ bg@infinitelybeta.com @ghoseb on Twitter Slides on - http://bit.ly/gnunify-clojure Infinitely Beta is recruiting smart hackers! http://infinitelybeta.com/jobs/ CC BY SA 31 / 31