SlideShare a Scribd company logo
'GETTING' CLOJURE'GETTING' CLOJURE
'(PARENTHESES ARE JUST HUGS FOR YOUR CODE)'(PARENTHESES ARE JUST HUGS FOR YOUR CODE)
Created by /Jason Lewis Gary Trakhman
Javascript
            function(){
              return 5;
            }
          
FUNCTIONSFUNCTIONS
Put some parens around it, kill the braces
            (function()
              return 5;
              )
          
Change 'function' to 'fn', makes args into a vector
            (fn []
              return 5;
              )
          
Kill the 'return', last thing's always returned.
Welcome to Clojure.
            (fn [] 5)
          
Move the left parenthesis over a bit more...
Done.
            someFunction(arg1, arg2, arg3);
          
            (someFunction arg1 arg2 arg3)
          
CALLING STUFFCALLING STUFF
THIS ISN'T AN ACCIDENTTHIS ISN'T AN ACCIDENT
Javascript is 'Lisp in C's Clothing'
Says Crockford:
http://www.crockford.com/javascript/javascript.html
PUT ANOTHER WAY...PUT ANOTHER WAY...
Q: Why do you think we've gotten so much mileage out of
javascript?
A: Lisp is very powerful, and it will never die
Should look familiar
Don't freak out
DON'T FREAK OUT
{:key1 5,
 :key2 nil}
[1 2 3 4 "five"]
          
[1 [2] #{3} {4 4} (constantly 5)]
          
=> (range 10)
(0 1 2 3 4 5 6 7 8 9)
=> (take 11 (range))
(0 1 2 3 4 5 6 7 8 9 10)
=> (last (range)) ;;Hope you don't mind waiting a long time.
          
DATADATA
Evals to...
;; semicolons are comments, commas are ignored,
;; check out this weird hash­map
{:a­keyword 5,
 "a string key" "a string value",
 ["a" :vector "acting" :as [:a :compound] "key"]
 (fn [] "a no­arg function
that returns this multi­line string,
the function itself is the value"),
 + '(functions can be keys too, and when
you quote symbols, you just
have symbols, not what they represent)}
          
{:a­keyword 5, "a string key" "a string value",
["a" :vector "acting" :as [:a :compound] "key"]
#<user$eval331$fn__332 user$eval331$fn__332@a585ef>,
#<core$_PLUS_ clojure.core$_PLUS_@20a12d8f>
(functions can be keys too and when you quote symbols
 you just have symbols not what they represent)}
          
EVERYTHING IS DATAEVERYTHING IS DATA
ANYTHING CAN BE A KEY, BECAUSEANYTHING CAN BE A KEY, BECAUSE
1. Every object is also a 'value'
2. Values have true equality
3. Values Never Change (Immutability)
4. Without immutability, objects are just buckets in memory
...have you ever trusted a bucket with no values?
Q: Why is this big news?
A: I can write code and rest assured that other parts of my
program can't change the data that I'm working on.
Q: But I thought every program is simply a short-lived http
request handler that talks to a database? We just throw the
program state out after every request!
A: Well, that's one way to do it.
http://www.ibm.com/developerworks/library/wa-aj-
multitier2/
NODE.JS...NODE.JS...
http://www.andrerodrigues.me/isel-
workshop/intro.html#/24
NODE.JS... IS NOTHING NEWNODE.JS... IS NOTHING NEW
We can write our own loops
Node.js assumes threaded programming is hard, and
throws out the baby with the bath-water
Threaded programming is hard without real 'Data' or
'Values'
Composition of any sort is simpler with data
APPROXIMATING NODE.JSAPPROXIMATING NODE.JS
'Agents' are asynchronous queues, sharing threadpools to
do work, storing the last value returned.
(defn inc­last [val]
  (conj val (inc (last val))))
;; We make a sequence of 10 inc­last tasks,
;; then follow­up with a 'println' task
(def tasks
  (concat (repeat 10 inc­last)
          [(fn [val]
             (println val)
             val)]))
            
;; starts off with a value of [0]
(let [a (agent [0])]
  (doseq [t tasks]
    (send a t)))
;; prints: [0 1 2 3 4 5 6 7 8 9 10]
          
Agents are not values, they are mutable references with
asynchronous semantics
Clojure has other mutable references types, acting as
'containers' for values, for various use cases.
Nothing prevents you from making your own.
(let [f (future (do­a­bunch­of­stuff))] ;; in another thread
  (do­stuff­in­this­thread)
  ;; return the value in f, blocking if it's not finished
  (deref f))
        
MORE!MORE!
Basically,
Clojure promotes your ability to do whatever you want, by
simplifying things to their bare essence.
WHAT WE REALLY WANTWHAT WE REALLY WANT
Tools that let us
1. Compose Systems
2. Change our minds
3. Re-use components in different contexts, processes,
servers, etc..
Data/Values give us the ability to decouple things easily
'(code is data)
BRAINSPLODEBRAINSPLODE
Read-Eval-Print-Loop
(class (read­string "(+ 1 2)"))
;; clojure.lang.PersistentList
(map class (read­string "(+ 1 2)"))
;; (clojure.lang.Symbol java.lang.Long java.lang.Long)
          
R-E-P-LR-E-P-L
1. Read: (read-string "(+ 1 2)") => '(+ 1 2)
2. Eval: (eval '(+ 1 2)) => 3
3. What if there's something in the middle?
This is only the beginning
(defn only­even!
 [val]
 (if (and (integer? val) (odd? val))
   (inc val)
   val))
(map only­even! (read­string "(+ 1 2)"))
;; '(+ 2 2)
(eval (map only­even! (read­string "(+ 1 2)")))
;; 4
          
Everybody likes chaining, right?
How is this implemented? Is this reusable?
$("#p1").css("color","red").slideUp(2000).slideDown(2000);
          
What if, as a library author, you could just not write that fluent
interface code at all?
(use 'clojure.string)
;; These are equivalent
(map trim (split (upper­case "hola, world") #","))
;; ("HOLA" "WORLD")
(­> "hola, world"
    upper­case
    (split #",")
    (­>> (map trim)))
;; ("HOLA" "WORLD")
          
Really useful when you're doing a lot of collection operations,
filtering, etc.
(­>> (range)
     (filter even?)
     (map (partial * 2))
     (take 10)
     (into []))
;; [0 4 8 12 16 20 24 28 32 36]
;; versus
(into []
      (take 10 (map (partial * 2)
                    (filter even? (range)))))
          
1. I find the flat one easier to think about.
2. Semantically equivalent.
3. No burden on implementing code. Functions don't care
about how they're used.
Giving the user choices is more effective with more powerful
languages. Leads to simple, composable libraries.
Let's look at a real one.
(defmacro lazy­seq
  "Takes a body of expressions that returns an ISeq or nil, and yields
  a Seqable object that will invoke the body only the first time seq
  is called, and will cache the result and return it on all subsequent
  seq calls. See also ­ realized?"
  {:added "1.0"}
  [& body]
  (list 'new 'clojure.lang.LazySeq (list* '^{:once true} fn* [] body)))
;; simply returns a list, allocates a Java object (LazySeq) and wraps
;; your expressions in a function
(macroexpand­1 '(lazy­seq ANYTHING1 ANYTHING2))
;; '(new clojure.lang.LazySeq (fn* [] ANYTHING1 ANYTHING2))
          
MACROSMACROS
Let's create an infinite sequence representing a square-wave
--__--__--__--__
No mutable variables
(defn square­wave
  "t is the period for a half­cycle"
  [t]
  (letfn
    [(osc [cur­value so­far]
       (let [so­far (mod so­far t)
             next­val (if (zero? so­far)
                        (­ cur­value)
                        cur­value)]
         (cons next­val
               (lazy­seq (osc next­val
                              (inc so­far))))))]
    (osc 1 0)))
          
(take 10 (square­wave 3))
;; (­1 ­1 ­1 1 1 1 ­1 ­1 ­1 1)
          
CALL TO ACTIONCALL TO ACTION
1. Learn Clojure
2. Build cool things
3. Screencasts!
(You ruby guys really know how to make good screencasts)
DEMO TIMEDEMO TIME
CLOJURE ON THE WEBCLOJURE ON THE WEB
Now clone this:
https://github.com/canweriotnow/bohjure
RESOURCESRESOURCES
Clojure: http://clojure.org
Fun Exercises: http://www.4clojure.com
Cheatsheets: http://clojure.org/cheatsheet
Building: https://github.com/technomancy/leiningen
Insight: http://www.youtube.com/user/ClojureTV
Community docs: http://clojuredocs.org
Blogs: http://planet.clojure.in
Light Table: http://www.lighttable.com
this doc: http://gtrak.github.io/bohconf.clojure
MORE DEMO TIMEMORE DEMO TIME
THANKS FOR COMING!THANKS FOR COMING!
WE ARE:WE ARE:
Gary Trakhman
Software Engineer at
@gtrakGT
Revelytix, Inc.
Jason Lewis
CTO at
@canweriotnow
An Estuary, LLC

More Related Content

What's hot (20)

PPTX
Introduction to Ecmascript - ES6
Nilesh Jayanandana
 
PDF
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Codemotion
 
ODP
ES6 PPT FOR 2016
Manoj Kumar
 
PPTX
Modern JS with ES6
Kevin Langley Jr.
 
PDF
JavaScript - new features in ECMAScript 6
Solution4Future
 
PDF
How to Vim - for beginners
Marcin Rogacki
 
PDF
Steady with ruby
Christopher Spring
 
KEY
jRuby: The best of both worlds
Christopher Spring
 
PDF
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
Codemotion
 
PDF
ES2015 (ES6) Overview
hesher
 
PDF
Introduction into ES6 JavaScript.
boyney123
 
PPTX
The Promised Land (in Angular)
Domenic Denicola
 
PDF
Akka tips
Raymond Roestenburg
 
KEY
EventMachine for RubyFuZa 2012
Christopher Spring
 
PDF
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
jeffz
 
PDF
Swift - One step forward from Obj-C
Nissan Tsafrir
 
PDF
Let'swift "Concurrency in swift"
Hyuk Hur
 
PDF
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Codemotion
 
PPTX
ES6 in Real Life
Domenic Denicola
 
PDF
The Ring programming language version 1.8 book - Part 82 of 202
Mahmoud Samir Fayed
 
Introduction to Ecmascript - ES6
Nilesh Jayanandana
 
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Codemotion
 
ES6 PPT FOR 2016
Manoj Kumar
 
Modern JS with ES6
Kevin Langley Jr.
 
JavaScript - new features in ECMAScript 6
Solution4Future
 
How to Vim - for beginners
Marcin Rogacki
 
Steady with ruby
Christopher Spring
 
jRuby: The best of both worlds
Christopher Spring
 
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
Codemotion
 
ES2015 (ES6) Overview
hesher
 
Introduction into ES6 JavaScript.
boyney123
 
The Promised Land (in Angular)
Domenic Denicola
 
EventMachine for RubyFuZa 2012
Christopher Spring
 
The Evolution of Async-Programming on .NET Platform (.Net China, C#)
jeffz
 
Swift - One step forward from Obj-C
Nissan Tsafrir
 
Let'swift "Concurrency in swift"
Hyuk Hur
 
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Codemotion
 
ES6 in Real Life
Domenic Denicola
 
The Ring programming language version 1.8 book - Part 82 of 202
Mahmoud Samir Fayed
 

Viewers also liked (17)

PDF
AI is the New UI - Tech Vision 2017 Trend 1
Accenture Technology
 
PPTX
Measuring Success in the Lean IT World
Lean IT Association
 
PPTX
Putting the Puzzle Together: Integrating Emerging Best Pracitces
Lean IT Association
 
PPTX
The Enemy Within: Stopping Advanced Attacks Against Local Users
Tal Be'ery
 
PDF
Improve your Retention with this One Change - David Cancel, CEO at Drift
SaaStock
 
PPTX
Zimbra propulsé par le n°1 de l'hébergement critique
Cloud Temple
 
PDF
Achieving Meaningful Exits in SaaS - Mark MacLeod - Founder at SurePath Capit...
SaaStock
 
PDF
Aben Resources - Investor Presentation
Company Spotlight
 
PDF
L'analytics pour les publishers conférence aadf
Prénom Nom de famille
 
PPTX
Building a Pluggable Analytics Stack with Cassandra (Jim Peregord, Element Co...
DataStax
 
PDF
Everest Group FIT matrix for Robotic Process Automation (rpa) technology
UiPath
 
PPTX
Le web design - fullCONTENT
Agence fullCONTENT
 
PDF
Le Fonds de soutien à l'investissement local: un succès qui bénéficie à 80% a...
Ministère de l'Aménagement du territoire, de la Ruralité et des collectivités territoriales
 
PDF
Comparison of Open Source Frameworks for Integrating the Internet of Things
Kai Wähner
 
PDF
Five Rules of the Insurance Game
University of South Florida
 
PDF
Machine Shop 2020 - Digital Manufacturing Decoded
Sandvik Coromant
 
PDF
Levée du secret professionnel : oser faire marche arrière
JLMB
 
AI is the New UI - Tech Vision 2017 Trend 1
Accenture Technology
 
Measuring Success in the Lean IT World
Lean IT Association
 
Putting the Puzzle Together: Integrating Emerging Best Pracitces
Lean IT Association
 
The Enemy Within: Stopping Advanced Attacks Against Local Users
Tal Be'ery
 
Improve your Retention with this One Change - David Cancel, CEO at Drift
SaaStock
 
Zimbra propulsé par le n°1 de l'hébergement critique
Cloud Temple
 
Achieving Meaningful Exits in SaaS - Mark MacLeod - Founder at SurePath Capit...
SaaStock
 
Aben Resources - Investor Presentation
Company Spotlight
 
L'analytics pour les publishers conférence aadf
Prénom Nom de famille
 
Building a Pluggable Analytics Stack with Cassandra (Jim Peregord, Element Co...
DataStax
 
Everest Group FIT matrix for Robotic Process Automation (rpa) technology
UiPath
 
Le web design - fullCONTENT
Agence fullCONTENT
 
Le Fonds de soutien à l'investissement local: un succès qui bénéficie à 80% a...
Ministère de l'Aménagement du territoire, de la Ruralité et des collectivités territoriales
 
Comparison of Open Source Frameworks for Integrating the Internet of Things
Kai Wähner
 
Five Rules of the Insurance Game
University of South Florida
 
Machine Shop 2020 - Digital Manufacturing Decoded
Sandvik Coromant
 
Levée du secret professionnel : oser faire marche arrière
JLMB
 
Ad

Similar to 'Getting' Clojure - '(parentheses are just hugs for your code) (20)

PDF
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
PDF
Javascript: the important bits
Chris Saylor
 
PDF
Coding in Style
scalaconfjp
 
PDF
CoffeeScript
Scott Leberknight
 
PDF
Designing with Groovy Traits - Gr8Conf India
Naresha K
 
PDF
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
PDF
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
hwilming
 
PDF
Ceylon idioms by Gavin King
UnFroMage
 
PDF
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
PDF
The Ring programming language version 1.3 book - Part 57 of 88
Mahmoud Samir Fayed
 
PDF
Clojure made-simple - John Stevenson
JAX London
 
PPTX
Kotlin Coroutines and Rx
Shaul Rosenzwieg
 
KEY
(map Clojure everyday-tasks)
Jacek Laskowski
 
PPT
[ “Love", :Ruby ].each { |i| p i }
Herval Freire
 
PPTX
Clojure And Swing
Skills Matter
 
PDF
Asynchronous programming done right - Node.js
Piotr Pelczar
 
PDF
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
 
PDF
Kotlin: maybe it's the right time
Davide Cerbo
 
PDF
JavaScript Execution Context
Juan Medina
 
PDF
Functional Programming with Groovy
Arturo Herrero
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
 
Javascript: the important bits
Chris Saylor
 
Coding in Style
scalaconfjp
 
CoffeeScript
Scott Leberknight
 
Designing with Groovy Traits - Gr8Conf India
Naresha K
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
hwilming
 
Ceylon idioms by Gavin King
UnFroMage
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
Philip Schwarz
 
The Ring programming language version 1.3 book - Part 57 of 88
Mahmoud Samir Fayed
 
Clojure made-simple - John Stevenson
JAX London
 
Kotlin Coroutines and Rx
Shaul Rosenzwieg
 
(map Clojure everyday-tasks)
Jacek Laskowski
 
[ “Love", :Ruby ].each { |i| p i }
Herval Freire
 
Clojure And Swing
Skills Matter
 
Asynchronous programming done right - Node.js
Piotr Pelczar
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
 
Kotlin: maybe it's the right time
Davide Cerbo
 
JavaScript Execution Context
Juan Medina
 
Functional Programming with Groovy
Arturo Herrero
 
Ad

Recently uploaded (20)

PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Biography of Daniel Podor.pdf
Daniel Podor
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
July Patch Tuesday
Ivanti
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 

'Getting' Clojure - '(parentheses are just hugs for your code)