SlideShare a Scribd company logo
Clojure


    John Vlachoyiannis
         @jonromero
   jon@emotionull.com
Http://jon.is.emotionull.com
What is Clojure?
Ok, what is Lisp?
“Lisp is worth learning for the profound
  enlightenment experience you will have
when you finally get it; that experience will
make you a better programmer for the rest
of your days, even if you never actually use
              Lisp itself a lot."


   Eric S. Raymond, "How to Become a
                Hacker".
“LISP stands for: Lots of Insane Stupid
            Parentheses”

             Anonymous
The Truth about Lisp
LISt Processing
              LIS
●   Second oldest high-level language (first is
    Fortran)
●   Code as Data (Homoiconic)
●   Perfect for Domain-specific languages
    (DSL)
●   Exploratory programming
Clojure
●   Lisp in JVM
●   Concurrent programming
●   Dynamic Development (REPL)
●   Lazy sequences
●   No side effects   (almost)
Enter Clojure
Everything is code
(println "Hello World")




function        argument
Everything is data
(println "Hello World")
list


       symbol          string
●   Integers – 1234567891234
●   Doubles – 3.14. BigDecimals – 3.14M
●   Ratios – 22/4
●   Strings – '”foo”, Character – a b c
●   Symbols – foo, Keywords :foo
●   Booleans – true false, Null – nil
●   Regex patterns – #”[a-zA-Z0-9]|
Data structures
●   Lists
   (1 2 3 4), (foo bar baz), (list 1 2 3)
    ●


● Vectors


   [1 2 3], [foo bar], (vector 1 2 3)
    ●


● Maps


   {:a 1 :b 2 :c 3}
    ●


● Sets


    ●   #{foo bar}
“It is better to have 100
functions operate on one data
   structure than to have 10
 functions operate on 10 data
            Structures.”

        Alan J. Perlis
clojure might be a better
      java than java
public class StringUtils {
   public static boolean isBlank(String str) {
      int strLen;
      if (str == null || (strLen = str.length()) == 0) {
          return true;
      }
      for (int i = 0; i < strLen; i++) {
          if ((Character.isWhitespace(str.charAt(i)) ==
false)) {
              return false;
          }
      }
      return true;
   }
}
public class StringUtils {
   public isBlank(str) {
      if (str == null || (strLen = str.length()) == 0) {
          return true;
      }
      for (i = 0; i < strLen; i++) {
          if ((Character.isWhitespace(str.charAt(i)) ==
false)) {
              return false;
          }
      }
      return true;
   }
}
public isBlank(str) {
  if (str == null || (strLen = str.length()) == 0) {
      return true;
  }
  for (i = 0; i < strLen; i++) {
      if ((Character.isWhitespace(str.charAt(i)) == false))
          return false;
      }
  }
  return true;
}
public isBlank(str) {
  if (str == null || (strLen = str.length()) == 0) {
      return true;
  }

    every (ch in str) {
       Character.isWhitespace(ch);
    }
    return true;
}
public isBlank(str) {
  every (ch in str) {
      Character.isWhitespace(ch);
  }
}
(defn blank? [s]
  (every? #(Character/isWhitespace %) s))
Clojure vs Java code
●   Side-effect free      ●   Error prone
●   Easy to (unit) test   ●   Not so easy
●   Lazy collection       ●   Only one element
●   Any element           ●   Only with chars
●   Slower                ●   Faster
●   Data manipulation     ●   If/for/while code
●   Exploratory           ●   Design Is Law
Clojure is a functional language
●   Functions are first-class objects
●   Data is immutable
●   Functions are pure
So what?
●   Simple: no loops, variables or mutable
    state
●   Thread-safe: no locking
●   Parallelizable: map/reduce anyone?
●   Generic: data is always data
●   Easy to test: same input, same output
user=> (println "hello world")
| hello world
-> nil
user=> (defn hello [name]
           (str "Hello, " name))
#'user/hello
(hello "Clojure")
(.toUpperCase “hello”)
(str “hello” “ “ “world”)
(+ 1 3 4 (* 5 6))
(defn greeting
"Returns a greeting of the form 'Hello, username.'"
[username]
(str "Hello, " username))
(greeting "world")
user=> (doc greeting)
              -------------------------
               exploring/greeting
                  ([username])
Returns a greeting of the form 'Hello, username.'
(defn is-small? [number]
   (if (< number 100)
          "yes" ))
(is-small? 50)
     "yes"
(is-small? 50000)
       nil
(defn is-small? [number]
   (if (< number 100)
           "yes"
           "no" ))
Solving problems
●   Experiment with the problem
●   Create your data structures
●   Data transformations
●   Write code that writes code for you
    (macros)
●   Create a mini language (a DSL)
Java in Clojure
●   Yeap
Clojure in Java
●   Yeap
Clojure in Clojure
●   Yeap, yeap
Java in Clojure


java           new Widget(“foo”)

clojure        (Widget. “foo”)




java           dialog.show()

clojure        (.show dialog)
Tools
●   Emacs + SLIME
●   ViMClojure
●   Enclojure + Intellij IDEA
●   Counterclockwise + Eclipse
●   Leiningen
Clojure is not a just a new language
Is another, simplier way to solve problems
Thanks! Questions?
   @jonromero
Ad

Recommended

Java8 and Functional Programming
Java8 and Functional Programming
Yiguang Hu
 
Kotlin workshop 2018-06-11
Kotlin workshop 2018-06-11
Åsa Pehrsson
 
Clojure intro
Clojure intro
Basav Nagur
 
Scala taxonomy
Scala taxonomy
Radim Pavlicek
 
The Ring programming language version 1.5.2 book - Part 6 of 181
The Ring programming language version 1.5.2 book - Part 6 of 181
Mahmoud Samir Fayed
 
Yin Yangs of Software Development
Yin Yangs of Software Development
Naveenkumar Muguda
 
JavaScript Data Types
JavaScript Data Types
Charles Russell
 
05. haskell streaming io
05. haskell streaming io
Sebastian Rettig
 
Tour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processor
Tatu Saloranta
 
The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202
Mahmoud Samir Fayed
 
Pune Clojure Course Outline
Pune Clojure Course Outline
Baishampayan Ghose
 
Learning groovy -EU workshop
Learning groovy -EU workshop
adam1davis
 
Head First Java Chapter 1
Head First Java Chapter 1
Tom Henricksen
 
Introduction to Groovy (Serbian Developer Conference 2013)
Introduction to Groovy (Serbian Developer Conference 2013)
Joachim Baumann
 
Python internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvand
irpycon
 
Fluent14
Fluent14
Brendan Eich
 
Just Kotlin
Just Kotlin
Ismail Habib Muhammad
 
Introduction to clojure
Introduction to clojure
Abhishek Mahawar
 
Simple Jackson with DropWizard
Simple Jackson with DropWizard
Tatu Saloranta
 
Jackson beyond JSON: XML, CSV
Jackson beyond JSON: XML, CSV
Tatu Saloranta
 
Writing Groovy DSLs
Writing Groovy DSLs
adam1davis
 
JavaScript Foundations Day1
JavaScript Foundations Day1
Troy Miles
 
Programming with Freedom & Joy
Programming with Freedom & Joy
Hildeberto Mendonça
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
krmboya
 
Structure and interpretation of computer programs modularity, objects, and ...
Structure and interpretation of computer programs modularity, objects, and ...
bdemchak
 
C# Starter L03-Utilities
C# Starter L03-Utilities
Mohammad Shaker
 
Hackersnl
Hackersnl
chriseidhof
 
Hw09 Hadoop + Clojure
Hw09 Hadoop + Clojure
Cloudera, Inc.
 
Clojure class
Clojure class
Aysylu Greenberg
 
Kotlin for Android Development
Kotlin for Android Development
Speck&Tech
 

More Related Content

What's hot (20)

Tour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processor
Tatu Saloranta
 
The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202
Mahmoud Samir Fayed
 
Pune Clojure Course Outline
Pune Clojure Course Outline
Baishampayan Ghose
 
Learning groovy -EU workshop
Learning groovy -EU workshop
adam1davis
 
Head First Java Chapter 1
Head First Java Chapter 1
Tom Henricksen
 
Introduction to Groovy (Serbian Developer Conference 2013)
Introduction to Groovy (Serbian Developer Conference 2013)
Joachim Baumann
 
Python internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvand
irpycon
 
Fluent14
Fluent14
Brendan Eich
 
Just Kotlin
Just Kotlin
Ismail Habib Muhammad
 
Introduction to clojure
Introduction to clojure
Abhishek Mahawar
 
Simple Jackson with DropWizard
Simple Jackson with DropWizard
Tatu Saloranta
 
Jackson beyond JSON: XML, CSV
Jackson beyond JSON: XML, CSV
Tatu Saloranta
 
Writing Groovy DSLs
Writing Groovy DSLs
adam1davis
 
JavaScript Foundations Day1
JavaScript Foundations Day1
Troy Miles
 
Programming with Freedom & Joy
Programming with Freedom & Joy
Hildeberto Mendonça
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
krmboya
 
Structure and interpretation of computer programs modularity, objects, and ...
Structure and interpretation of computer programs modularity, objects, and ...
bdemchak
 
C# Starter L03-Utilities
C# Starter L03-Utilities
Mohammad Shaker
 
Hackersnl
Hackersnl
chriseidhof
 
Hw09 Hadoop + Clojure
Hw09 Hadoop + Clojure
Cloudera, Inc.
 
Tour de Jackson: Forgotten Features of Jackson JSON processor
Tour de Jackson: Forgotten Features of Jackson JSON processor
Tatu Saloranta
 
The Ring programming language version 1.8 book - Part 7 of 202
The Ring programming language version 1.8 book - Part 7 of 202
Mahmoud Samir Fayed
 
Learning groovy -EU workshop
Learning groovy -EU workshop
adam1davis
 
Head First Java Chapter 1
Head First Java Chapter 1
Tom Henricksen
 
Introduction to Groovy (Serbian Developer Conference 2013)
Introduction to Groovy (Serbian Developer Conference 2013)
Joachim Baumann
 
Python internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvand
irpycon
 
Simple Jackson with DropWizard
Simple Jackson with DropWizard
Tatu Saloranta
 
Jackson beyond JSON: XML, CSV
Jackson beyond JSON: XML, CSV
Tatu Saloranta
 
Writing Groovy DSLs
Writing Groovy DSLs
adam1davis
 
JavaScript Foundations Day1
JavaScript Foundations Day1
Troy Miles
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
krmboya
 
Structure and interpretation of computer programs modularity, objects, and ...
Structure and interpretation of computer programs modularity, objects, and ...
bdemchak
 
C# Starter L03-Utilities
C# Starter L03-Utilities
Mohammad Shaker
 

Similar to Clojure Small Intro (20)

Clojure class
Clojure class
Aysylu Greenberg
 
Kotlin for Android Development
Kotlin for Android Development
Speck&Tech
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
Introduction to clojure
Introduction to clojure
Abbas Raza
 
Poniendo Kotlin en producción a palos (Kotlin in production, the hard way)
Poniendo Kotlin en producción a palos (Kotlin in production, the hard way)
Andrés Viedma Peláez
 
Clojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
JAX London
 
Clojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
Jan Kronquist
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
Miles Sabin
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
 
Ceylon - the language and its tools
Ceylon - the language and its tools
Max Andersen
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
Miles Sabin
 
Music as data
Music as data
John Vlachoyiannis
 
Scala
Scala
suraj_atreya
 
Clojure And Swing
Clojure And Swing
Skills Matter
 
Getting started with Clojure
Getting started with Clojure
John Stevenson
 
Beyond java8
Beyond java8
Muhammad Durrah
 
Clojure
Clojure
alandipert
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
Jimin Hsieh
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Tudor Dragan
 
Kotlin for Android Development
Kotlin for Android Development
Speck&Tech
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
Introduction to clojure
Introduction to clojure
Abbas Raza
 
Poniendo Kotlin en producción a palos (Kotlin in production, the hard way)
Poniendo Kotlin en producción a palos (Kotlin in production, the hard way)
Andrés Viedma Peláez
 
Clojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
JAX London
 
Clojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
Jan Kronquist
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
Miles Sabin
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
 
Ceylon - the language and its tools
Ceylon - the language and its tools
Max Andersen
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
Miles Sabin
 
Getting started with Clojure
Getting started with Clojure
John Stevenson
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
Jimin Hsieh
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Tudor Dragan
 
Ad

More from John Vlachoyiannis (6)

Making gazillion with cryptocurrencies
Making gazillion with cryptocurrencies
John Vlachoyiannis
 
The most epic advice to become an angel investor
The most epic advice to become an angel investor
John Vlachoyiannis
 
Music as Data - Ignite 2011 SF
Music as Data - Ignite 2011 SF
John Vlachoyiannis
 
This is Appengine! 300 reasons to love Google AppEngine
This is Appengine! 300 reasons to love Google AppEngine
John Vlachoyiannis
 
Rain up presentation (erlang factory)
Rain up presentation (erlang factory)
John Vlachoyiannis
 
Metaprogramming in Ruby
Metaprogramming in Ruby
John Vlachoyiannis
 
Making gazillion with cryptocurrencies
Making gazillion with cryptocurrencies
John Vlachoyiannis
 
The most epic advice to become an angel investor
The most epic advice to become an angel investor
John Vlachoyiannis
 
Music as Data - Ignite 2011 SF
Music as Data - Ignite 2011 SF
John Vlachoyiannis
 
This is Appengine! 300 reasons to love Google AppEngine
This is Appengine! 300 reasons to love Google AppEngine
John Vlachoyiannis
 
Rain up presentation (erlang factory)
Rain up presentation (erlang factory)
John Vlachoyiannis
 
Ad

Recently uploaded (20)

Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
High Availability On-Premises FME Flow.pdf
High Availability On-Premises FME Flow.pdf
Safe Software
 
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
FME for Good: Integrating Multiple Data Sources with APIs to Support Local Ch...
Safe Software
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
AudGram Review: Build Visually Appealing, AI-Enhanced Audiograms to Engage Yo...
SOFTTECHHUB
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 

Clojure Small Intro