SlideShare a Scribd company logo
1 of 83
Download to read offline
CLOJURE WORKSHOP
println ("Hello, World")
(println "Hello, World")
SCALARS
nil
true
false
3.14
H
i
"Kittens are cute"
:hello
:foo/bar
'println
'clojure.core/println
COLLECTIONS
[1, 2, 3, 4]
[1 2 3 4]
[1 2 :three "four"]
{:foo 1, :bar 2}
{:foo 1 :bar 2}
{
"fizz" true
:bugs
false
[1 2 3] {:do "re"}
}
#{1 2 3}
'(1 2 3)
THE SEQUENCE
ABSTRACTION
(first [1 2 3])
(first [1 2 3])
; => 1
(first [1 2 3])
; => 1
(first '(1 2 3))
(first [1 2 3])
; => 1
(first '(1 2 3))
; => 1
(first [1 2 3])
; => 1
(first '(1 2 3))
; => 1
(first #{1 2 3})
(first [1 2 3])
; => 1
(first '(1 2 3))
; => 1
(first #{1 2 3})
; => 2
(first [1 2 3])
; => 1
(first '(1 2 3))
; => 1
(first #{1 2 3})
; => 2
(first {:one 1 :two 2})
(first [1 2 3])
; => 1
(first '(1 2 3))
; => 1
(first #{1 2 3})
; => 2
(first {:one 1 :two 2})
; => [:two 2]
(range 10)
(range 10)
;=> (0 1 2 3 4 5 6 7 8 9)
(take 5 (range))
(take 5 (range))
; => (0 1 2 3 4)
(defn fib [a b]
(cons a (lazy-seq (fib b (+ b a)))))
FUNCTIONS
println ("Hello, World")
(println "Hello, World")
(+ 40 2)
(+ 10 8 20 4)
(fn [name]
(println "Hello " name))
(def host "Thoughtworks")
(def greet
(fn [name]
(println "Hello " name)))
(def greet [name]
fn
(println "Hello " name))
(map inc [1 5 9])
(map inc [1 5 9])

=> [2 6 10]
(defn create-incrementor [increment-by]
(fn [number]
(+ number increment-by)))
(defn create-incrementor [increment-by]
(fn [number]
(+ number increment-by)))
(map (create-incrementor 7) [1 5 9])
(defn create-incrementor [increment-by]
(fn [number]
(+ number increment-by)))
(map (create-incrementor 7) [1 5 9])
=> [8 12 16]
REAL WORLD
AUTOMATED TESTS
(fact (split "a/b/c" #"/")
=> ["a" "b" "c"])
(tabular
(fact "The rules of Conway's life"
(alive? ?cell-status ?neighbor-count) => ?expected)
?cell-status
:alive
:alive
:alive
:alive

?neighbor-count
1
2
3
4

?expected
false
true
true
false

:dead
:dead
:dead

2
3
4

false
true
false)
SQL
(defdb prod
(postgres {:db "korma"
:user "db"
:password "dbpass"}))
 
(defentity address)
(defentity user
(has-one address))
 
(select user
(with address)
(fields :firstName :lastName :address.state)
(where {:email "korma@sqlkorma.com"}))
JSON
(ns examples.json
(:use cheshire.core))
(generate-string {:foo "bar" :baz 5})
=> {“foo”: “bar”, “baz”: 5}
(parse-string "{"foo":"bar"}")
=> {"foo" "bar"}
XML PARSING
(ns examples.xml
(:use clojure.xml)
(:import java.io.File))
(def xml-doc
(parse (File. "calendar.xml")))
(get-in xml-doc [:content 1 :content 0 :content])
=> [“Rover’s birthday”]
HTML
(ns examples.templating
(:use hiccup.core)
 
(html [:span {:class "foo"} "bar"])
=> "<span class="foo">bar</span>"
 
(html [:ul
(for [x (range 1 4)]
[:li x])])
=> "<ul><li>1</li><li>2</li><li>3</li></ul>"
WEB
(ns hello-world
(:use compojure.core)
(:require [compojure.route :as route]))
(defroutes app
(GET "/" []
"<h1>Hello World</h1>")
(route/not-found
"<h1>Page not found</h1>"))
GUI
GUI
(ns seesaw.test.examples.slider
  (:use [seesaw core color border] seesaw.test.examples.example))
(defn make-frame []
  (frame
    :title "Slider Example"
    :content
      (horizontal-panel :items [
        (vertical-panel :items [
          "<html>Slide the sliders to change<br>the color to the right</html>"
          (slider :id :red
:min 0 :max 255)
          (slider :id :green :min 0 :max 255)
          (slider :id :blue :min 0 :max 255)])
        (canvas :id :canvas :border (line-border) :size [200 :by 200])])))
(defn update-color [root]
  (let [{:keys [red green blue]} (value root)]
    (config! (select root [:#canvas]) :background (color red green blue))))
(defexample []
  (let [root (make-frame)]
    (listen (map #(select root [%]) [:#red :#green :#blue]) :change
            (fn [e] (update-color root)))
    root))
FUNCTIONAL
PROGRAMMING
number = 1
 
while number < 20
if number % 3 == 0 && number % 5 == 0
puts "fizzbuzz"
elsif number % 3 == 0
puts "fizz"
elsif number % 5 == 0
puts "buzz"
else
puts number
end
 
number = number + 1
end
for number in 1..20
if number % 3 == 0 && number % 5 == 0
puts "fizzbuzz"
elsif number % 3 == 0
puts "fizz"
elsif number % 5 == 0
puts "buzz"
else
puts number
end
end
numbers = (0..20).map do |number|
if number % 3 == 0 && number % 5 == 0
"fizzbuzz"
elsif number % 3 == 0
"fizz"
elsif number % 5 == 0
"buzz"
else
number
end
end
 
puts numbers
(defn divisible-by? [divisor number]
(= 0 (mod number divisor)))
 
(defn fizz-buzzify [number]
(cond
(divisible-by? 15 number) "fizzbuzz"
(divisible-by? 3 number) "fizz"
(divisible-by? 5 number) "buzz"
:else number))
 
(def fizz-buzz (map fizz-buzzify (range)))
 
(mapv println (take 100 fizz-buzz))
RESOURCES
WEBSITES
CLOJURE.ORG
CLOJUREDOCS.ORG
CLOJARS.ORG
CLOJURE-DOC.ORG
VIDEO
YOUTUBE - CLOJURETV
INFOQ - CLOJURE TAG
BOOKS
CLOJURE PROGRAMMING
PROGRAMMING CLOJURE
CLOJURE IN ACTION
THE JOY OF CLOJURE
PRACTICAL CLOJURE
FP4OOP
SIMPLE MADE EASY
IMPLEMENTATIONS
Clojure (JVM)
ClojureScript
ClojureCLR
clojure-py
clojure-scheme
FIN
Questions?

More Related Content

What's hot

Python Developer's Daily Routine
Python Developer's Daily RoutinePython Developer's Daily Routine
Python Developer's Daily Routine
Maxim Avanov
 

What's hot (20)

(Fun clojure)
(Fun clojure)(Fun clojure)
(Fun clojure)
 
My First Source Code
My First Source CodeMy First Source Code
My First Source Code
 
Introduction functionalprogrammingjavascript
Introduction functionalprogrammingjavascriptIntroduction functionalprogrammingjavascript
Introduction functionalprogrammingjavascript
 
Python Developer's Daily Routine
Python Developer's Daily RoutinePython Developer's Daily Routine
Python Developer's Daily Routine
 
New
NewNew
New
 
FPBrno 2018-05-22: Benchmarking in elixir
FPBrno 2018-05-22: Benchmarking in elixirFPBrno 2018-05-22: Benchmarking in elixir
FPBrno 2018-05-22: Benchmarking in elixir
 
re3 - modern regex syntax with a focus on adoption
re3 - modern regex syntax with a focus on adoptionre3 - modern regex syntax with a focus on adoption
re3 - modern regex syntax with a focus on adoption
 
Let's golang
Let's golangLet's golang
Let's golang
 
clonehd01
clonehd01clonehd01
clonehd01
 
Sol9
Sol9Sol9
Sol9
 
Python sqlite3
Python sqlite3Python sqlite3
Python sqlite3
 
Elixir & Phoenix - fast, concurrent and explicit
Elixir & Phoenix - fast, concurrent and explicitElixir & Phoenix - fast, concurrent and explicit
Elixir & Phoenix - fast, concurrent and explicit
 
Rabia
RabiaRabia
Rabia
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
Ruby to Elixir - what's great and what you might miss
Ruby to Elixir - what's great and what you might missRuby to Elixir - what's great and what you might miss
Ruby to Elixir - what's great and what you might miss
 
Javascript ES6 generators
Javascript ES6 generatorsJavascript ES6 generators
Javascript ES6 generators
 
Python and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihunPython and rust 2018 pythonkorea jihun
Python and rust 2018 pythonkorea jihun
 
PubNative Tracker
PubNative TrackerPubNative Tracker
PubNative Tracker
 
tensorflow/keras model coding tutorial 勉強会
tensorflow/keras model coding tutorial 勉強会tensorflow/keras model coding tutorial 勉強会
tensorflow/keras model coding tutorial 勉強会
 
Exploring slides
Exploring slidesExploring slides
Exploring slides
 

Viewers also liked (8)

Promise list
Promise listPromise list
Promise list
 
Clojure at a post office
Clojure at a post officeClojure at a post office
Clojure at a post office
 
Advanced
AdvancedAdvanced
Advanced
 
Coordinating non blocking io melb-clj
Coordinating non blocking io melb-cljCoordinating non blocking io melb-clj
Coordinating non blocking io melb-clj
 
Capital budgeting’ OF FINANCIAL MANAGEMENT
Capital budgeting’ OF FINANCIAL MANAGEMENTCapital budgeting’ OF FINANCIAL MANAGEMENT
Capital budgeting’ OF FINANCIAL MANAGEMENT
 
комикс
комикскомикс
комикс
 
Majalah ict no.16 2013
Majalah ict no.16 2013Majalah ict no.16 2013
Majalah ict no.16 2013
 
Herbs That Cure Herpes
Herbs That Cure HerpesHerbs That Cure Herpes
Herbs That Cure Herpes
 

Similar to Basics

Useful javascript
Useful javascriptUseful javascript
Useful javascript
Lei Kang
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
Siva Arunachalam
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
kesav24
 
The Magnificent Seven
The Magnificent SevenThe Magnificent Seven
The Magnificent Seven
Mike Fogus
 

Similar to Basics (20)

Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101Girl Geek Dinners - Clojure 101
Girl Geek Dinners - Clojure 101
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Music as data
Music as dataMusic as data
Music as data
 
Lập trình Python cơ bản
Lập trình Python cơ bảnLập trình Python cơ bản
Lập trình Python cơ bản
 
A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009A Taste of Python - Devdays Toronto 2009
A Taste of Python - Devdays Toronto 2009
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
(first '(Clojure.))
(first '(Clojure.))(first '(Clojure.))
(first '(Clojure.))
 
All I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School AlgebraAll I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School Algebra
 
CQL 实现
CQL 实现CQL 实现
CQL 实现
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
Python for High School Programmers
Python for High School ProgrammersPython for High School Programmers
Python for High School Programmers
 
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
Elixir  -Tolerância a Falhas para Adultos - GDG CampinasElixir  -Tolerância a Falhas para Adultos - GDG Campinas
Elixir -Tolerância a Falhas para Adultos - GDG Campinas
 
funwithalgorithms.pptx
funwithalgorithms.pptxfunwithalgorithms.pptx
funwithalgorithms.pptx
 
Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기
 
[SI] Ada Lovelace Day 2014 - Tampon Run
[SI] Ada Lovelace Day 2014  - Tampon Run[SI] Ada Lovelace Day 2014  - Tampon Run
[SI] Ada Lovelace Day 2014 - Tampon Run
 
7 Python udf.pptx
7 Python udf.pptx7 Python udf.pptx
7 Python udf.pptx
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
 
Extending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::UtilExtending Operators in Perl with Operator::Util
Extending Operators in Perl with Operator::Util
 
Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2
 
The Magnificent Seven
The Magnificent SevenThe Magnificent Seven
The Magnificent Seven
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Basics