SlideShare a Scribd company logo
Introduction
                                            To
                                       Clojure
                               BBC lunch & learn, July 18th 2012
                       Renzo Borgatti, Developer in Test, A/V Team



Welcome to this introduction to the Clojure language. Clojure had a lot of attraction lately as
well other well known languages based on the functional paradigm like Erlang or inspired
from the functional paradigm like Scala. There is definitely a reason for the return of the
functional paradigm nowadays that we are going to explain briefly in this talk.

My name is Renzo Borgatti, blah blah
the functional re-emergence
        roots in λ-calculus 1930
      re-discovered with Lisp 1958



The functional paradigm has its root in the Lambda calculus, a method for notations and
manipulation of mathematical functions introduced by Alonso Church around 1930.
Lambda calculus was then rediscovered as a versatile programming tool by McCarthy in 1958
when Lisp was introduced as a programming language able to deal with mathematical
notation.
Moore’s failure for cpu clock
   but cpu density growing fast
  software is the new bottleneck
  need to design for concurrency



Moore’s law recently failed on one of its axis. CPU speed is not doubling or tripling every year
anymore. It used to be the case in the late ’90. But the demand of computing power is
growing as usual.

Hardware manufacturer resorted to other means to increase power, such as transistor
density. Right now is not uncommon to see cheap laptops sold with 4 cpu cores out of the
box. Change on chip density requires a change in software scalability. Software must be
written for concurrency to take advantage of multi-core architectures.
OOP encapsulates state
        changes overwrite state
      state has multiple observers
      concurrency requires locking
         locking is complicated



Object Oriented Programming confines state using specific language constructs like classes.
The Program flows as a series of state changes.
When state needs concurrent access it must be protected using locks because there could be
multiple computations going on at the same time.
A change on the state delete previous values and the history is lost
The problem is that “identity” and “values” are overlapping

A clear example is a date object. A date is created to hold a value, maybe the the hottest day
of the year. If there is a new record this year, that is the new hottest day. But what about the
previous one? Why it should be completely replaced by changing the date and removing the
information from the system? What about all the threads that were observing the value
producing metrics for the old date? Should that information being lost by changing the date
instance or should each thread just keep going observing the old value until they decide
otherwise?

State based languages are hard to understand and to debug. Looking at some method,
chances are you can’t be sure until runtime about what that method is supposed to behave in
certain condition. Sometimes even at runtime the portion of state influencing the
computation is so big that is impossible to handle correctly.

Concurrency based on locks is complicated, generating deadlock conditions and all sort of
synchronisation issues.
Clojure, Scala, F#, Erlang...
        focus on immutability
     semantic for changing values
     “new” model for concurrency



Hence why the resurgence of the “old” and “academic” functional model.

Why not Lisp or Haskell?

Clojure Scala and F# all have in common the fact that they are hosted, so interoperability with
known languages it’s easy. Erlang is a special case of non-hosted functional language that
became popular. Erlang is very focused on high availability and performs great in that kind of
environments.
A dynamically-typed
           jvm-based Lisp dialect

                           Rich Hickey
                              2007
                             now 1.4

What about Clojure in specific? Clojure is a relatively young programming language based on
Lisp but running on the JVM.

It comes out from the frustration of Rich Hickey developing highly concurrent systems as a
Java and .NET consultant.

Rich Hickey developed dotLisp for the .NET environment before Clojure.

He spent then 2.5 years designing and implementing Clojure. Clojure was officially
announced in 2007.
interactive
                               hosted
                              dynamic
                             it’s a Lisp
                             functional
                            concurrent

These are the main Clojure design principles. Clojure is a “consenting adults” language. It sits
someway between the functional pureness of Haskell and the lazy-evaluate-everything of
Scheme. Checking for functions that aren’t pure in Clojure is technically possible, but that
will make more than half of the JDK or CLR unusable.
interactive



          REPL read-eval-print loop
           suitable for exploration
          introspection capabilities
            fast development loop


                                                demo
Show off REPL in action:
- repl special variables *1 *2 *3 etc
- the content of (pst) after an exception
- doc searching and print sources
- (find-doc “some”)
- (use ‘clojure.repl) (source func)
hosted




        built with Java interop in mind
                use Java directly
                   no wrappers
              lots of syntatic sugar


                                                                          demo
-   java interop demo
-   (filter #(re-seq #"pper" (.getName %)) (seq (.getMethods String)))
-   (import 'java.util.Date) (def now (Date.))
-   (.. "" getClass getMethods)
dynamic




        less ceremony: speed
      concise: where’s my code
     ~1:1 ratio sudocode real code



Clojure is dynamic in two ways. It’s dynamically typed, so it doesn’t specify types. Explicit
typing would be more useful for a language that at compile time can check if the current
functions are producing side effects and issue warnings. For Clojure dynamic typing means to
be more concise and more flexible.

Second, Clojure it’s dynamic in the way programmers can approach development with it:
firing up a REPL, test live code that gets automatically re-evaluated (when needed) and tweak
the main program on the go. Less ceremony means speed: less code to type, less potential
bugs, code is more readable.

Conciseness measures the quantity of code needed to express a “task” in the language. When
the language is concise it’s easier for the programmer to focus on business logic. Potentially
a 1:1 ratio between sudocode and the actual code would be ideal.
dynamic




           by the way, not this kind...

                  ...of expressiveness!




That’s the APL one liner for the game of life.
http://catpad.net/michael/apl/
dynamic

     but instead of




                                            something like

This is the isBlank static method in StringUtils from Apache commons. I have a quiz for you. I
removed the name of the method. By reading the java and the clojure version of the same
behaviour, could you tell what the method is actually doing? If yes, was the Java or the
Clojure version more helpful?
It’s a Lisp




      homoiconic data as code
     powerful macro programming
         define new syntax



                                                                            demo
In Clojure everything that the compiler sees are just data structure although there is some
syntactic sugar to make it easier to program.

But before the compiler there is a Reader in Clojure which transforms the textual input into
data structures.

Homoiconic means just that, that everything is a data structure. Why this is important?
Because the syntax is much simpler and more abstract constructs can be built in term of a
bunch of primitives. It also make it easier for macro programming.

Macros are special constructs which are interpreted by the reader and will influence the final
output which is going to the compiler. With Macros you can effectively extend the language.
Clojure “when”, “for” or syntax like the arrow operator “->” are effectively macros.

(macroexpand '(when (= "a" "a") (def renzo ", renzo") (str "this is also true" renzo)))
(macroexpand '(for [x (range 10)] (str x)))
functional



        focus on immutability
      side-effects free functions
        caching and laziness
    “consenting adults” pureness



Finally, Clojure is functional. It should be already clear at this point of the presentation.
Clojure main data structures are immutable, requiring a specific semantic to be altered. Being
functional means that the output of a function can only be influenced by its inputs. The
parameters must hence be immutable. If they were mutable then the function would have a
chance to be impure by altering them.

When a function is pure there are no side effects so it is producing repeatable results which
are independent from the state of the system. Repeatable means caching can be
implemented easily. Laziness follows because there is no need to “render” the result of a
function until it’s actually needed. Laziness means more optimisation opportunities for the
compiler.

Clojure always allows you to skip all of that and introduce side effects all around. It does not
have the assignment operator though.
concurrent




   immutable core data structures
    constrained change semantic
         atom, ref, agent, var



                                                                          demo
Clojure has been built with a focus on concurrency. Main data structures are immutable
requiring special semantic to be altered. There are four types of clojure construct to alter
immutable structures.

Atoms are simple CAS (compare and swap) semantic. You create an atom and then you can
change it by just calling swap! on it passing the function that should alter the content of the
atom. The swap! will succeed or not, based on a comparison with the current value in the
atom. If the value is changed by another thread in the middle, the swap! will be attempted
again over the new value. Needless to say, the altering function needs to be side effects free.

Atoms cannot coordinate over multiple values. You need Refs for that. A ref is similar to a
database transaction. You need to open a transaction before attempting to change any of the
Refs. Transactions can be attempt an arbitrary number of times.

Agents are similar to Atoms in the sense that they are uncoordinated. But an action sent to an
Agent will be executed at some later point in time, on a thread pool.

Vars is thread-local state that can be altered by using the (binding) form. They can be used
where too many repeating parameters are unpractical (like Java).
Clojure is not a replacement
     not just for list comprehension
           radical approach
         steeper learning curve

                what about all those
                  parenthesis?

Clojure has not been built to be a replacement for Java as other languages. It was built with
imperative and state based languages drawbacks to solve the problem entirely.

Another thing that is valid for all functionally inspired languages is that the functional
paradigm is not about having functions as variables that can be sent around and used on
collections. Ruby and Python aren’t certainly functional but they are heavily based on closures
(aka lambdas). Scala is more functional in this respect but it allows assignment and support
object orientation with instance variables that are clearly used to obtain side effects.

If you come from another paradigm and usually programming in Java the Clojure learning
curve will be probably steeper than Groovy or Scala.

Java people tend to try to match parenthesis as soon as they see them. Brackets mostly
delimit scope and give structure to the code. Lispers don’t need to match parenthesis.
Who is using Clojure?

The always evolving lists:
http://dev.clojure.org/display/community/Clojure+Success+Stories
http://www.quora.com/Whos-using-Clojure-in-production
Clojure is a good hiring tool
            attract smart people
        diversify company mindset



There is an higher probability to attract the Lisp community with Clojure than Scala.

The Lisp community includes a very fine selected crowd of people who must have been in
deeply love with their language if they remained outside the mainstream languages for
something like half a century! Apart from jokes, the average mathematical and algorithmic
background of the Lisp community is very high and a nice addition for you team.

An useful link: the london clojurians jobs page (requires to join the mailing list):
- https://groups.google.com/forum/?fromgroups#!forum/london-clojurian-jobs
Scala                                     Clojure


           type system                        change semantic models
  complicated type system                          clever sequences
       actor concurrency                                no objects
       good java interops                           harder to recruit
       friendly java syntax                    top-notch java interops
        object/functional                       steeper learning curve
                                                    Lisp community




The not-definitive Scala to Clojure comparison chart in no specific order of priority.

The two languages have completely different philosophies but the impression is that at the
end they have more in common than expected.

There are hiring and people factors to consider when choosing one or the other. Clojure is a
radical approach that refuses objects as the main tool to model the world, especially a
concurrent world. Scala embraces both styles and let object oriented developers depart from
the paradigm when needed.

The choice between the two language is almost impossible to make outside a specific
context. They both have pro and cons that compensate each other on an absolute scale. What
should not happen in both cases is that you choose the language because you can “send
methods to collections and around”. There is much more about the functional paradigm that
has nothing to do with closures.
General resources
the main clojure website:
http://www.clojure.org
easily browsable documentation:
http://clojuredocs.org
the london clojure dojo and group:
http://londonclojurians.org
who is using Clojure?
http://dev.clojure.org/display/community/Clojure+Success+Stories
paper introducing lamda calculus to programmers:
http://www.cs.bham.ac.uk/~axj/pub/papers/lambda-calculus.pdf
introducing clojure in the organization:
http://blog.jayfields.com/2012/01/lessons-learned-while-introducing-new.html
BBC resources

The BBC clojure weekly dojo, every Thu 12:30 van gogh:
https://confluence.dev.bbc.co.uk/display/~renzo.borgatti@bbc.co.uk/clojure-ug
BBC Clojure forge mailing list:
https://lists.forge.bbc.co.uk/mailman/listinfo/clojure
BBC Clojure forge IRC channel:
#clojure
Talk

Slides PDF available here:
https://confluence.dev.bbc.co.uk/display/~renzo.borgatti@bbc.co.uk/clojure-ug
Please rate my talk:
sdfdfd
Video will be available soon
Me
@reborg
renzo.borgatti@bbc.co.uk
http://reborg.net
http://github.com/reborg
Questions?




Or, let me help...
if Java had closures today
       (they’ll be in Java 8)
would you still consider Scala or
             Groovy?

 Is it still worth learning a new
     language for that only?
(let [audience people-present-today]
  (map #(str “THANK YOU, ” %) audience))

More Related Content

PDF
Clojure A Dynamic Programming Language for the JVM
PDF
Clojure talk at Münster JUG
PDF
Clojure - An Introduction for Java Programmers
PDF
Clojure - An Introduction for Lisp Programmers
PDF
Clojure and The Robot Apocalypse
PDF
New Features Of JDK 7
PDF
Java 8 selected updates
PPTX
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Clojure A Dynamic Programming Language for the JVM
Clojure talk at Münster JUG
Clojure - An Introduction for Java Programmers
Clojure - An Introduction for Lisp Programmers
Clojure and The Robot Apocalypse
New Features Of JDK 7
Java 8 selected updates
Introduction of Java 8 with emphasis on Lambda Expressions and Streams

What's hot (20)

PDF
Java jdk-update-nov10-sde-v3m
PDF
Functional programming in scala
PPTX
Introduction to Scala
PDF
camel-scala.pdf
PDF
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
PPTX
Functional programming with Java 8
PDF
Lambda: A Peek Under The Hood - Brian Goetz
PDF
Ppl for students unit 4 and 5
PDF
Java SE 8 best practices
PPTX
The Road to Lambda - Mike Duigou
PPTX
Overview Of .Net 4.0 Sanjay Vyas
PDF
Java SE 8 library design
PPTX
Objective-c for Java Developers
PDF
An Introduction to Java Compiler and Runtime
PDF
Core Java Tutorial
PDF
I know Java, why should I consider Clojure?
PPT
Core java
PDF
Java Course 7: Text processing, Charsets & Encodings
PDF
Functional programming with Java 8
PPTX
Core java
Java jdk-update-nov10-sde-v3m
Functional programming in scala
Introduction to Scala
camel-scala.pdf
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
Functional programming with Java 8
Lambda: A Peek Under The Hood - Brian Goetz
Ppl for students unit 4 and 5
Java SE 8 best practices
The Road to Lambda - Mike Duigou
Overview Of .Net 4.0 Sanjay Vyas
Java SE 8 library design
Objective-c for Java Developers
An Introduction to Java Compiler and Runtime
Core Java Tutorial
I know Java, why should I consider Clojure?
Core java
Java Course 7: Text processing, Charsets & Encodings
Functional programming with Java 8
Core java
Ad

Viewers also liked (8)

PDF
Clojure Intro
PDF
Trabajo práctico sobre Clojure, Evaluación de un Lenguaje de Programación
PPT
Clojure
PPTX
Introduction to Clojure and why it's hot for Sart-Ups
PDF
Clojure: Java y Lisp, unidos
PPT
Fase 5 ciclo for
KEY
Clojure入門
KEY
Functional programming in clojure
Clojure Intro
Trabajo práctico sobre Clojure, Evaluación de un Lenguaje de Programación
Clojure
Introduction to Clojure and why it's hot for Sart-Ups
Clojure: Java y Lisp, unidos
Fase 5 ciclo for
Clojure入門
Functional programming in clojure
Ad

Similar to Introduction to Clojure (20)

PDF
Seeking Clojure
PDF
Languages used by web app development services remotestac x
PDF
Get Functional Programming with Clojure
KEY
Java Closures
PDF
Functional programming in Python 1st Edition David Mertz
PDF
The Rise of Functional Programming
PDF
Principled io in_scala_2019_distribution
PDF
Functional programming in Python 1st Edition David Mertz
PDF
PDF
Fun with Functional Programming in Clojure
PDF
Ruby on Rails (RoR) as a back-end processor for Apex
PDF
A Taste of Clojure
PDF
Something for Nothing
PDF
Introduction to functional programming
PDF
Thinking Functionally with Clojure
PDF
Thinking Functionally - John Stevenson - Codemotion Rome 2017
PDF
Functional programming is the most extreme programming
PPTX
Scala - The Simple Parts, SFScala presentation
KEY
Polyglot and Functional Programming (OSCON 2012)
PPTX
Stay fresh
Seeking Clojure
Languages used by web app development services remotestac x
Get Functional Programming with Clojure
Java Closures
Functional programming in Python 1st Edition David Mertz
The Rise of Functional Programming
Principled io in_scala_2019_distribution
Functional programming in Python 1st Edition David Mertz
Fun with Functional Programming in Clojure
Ruby on Rails (RoR) as a back-end processor for Apex
A Taste of Clojure
Something for Nothing
Introduction to functional programming
Thinking Functionally with Clojure
Thinking Functionally - John Stevenson - Codemotion Rome 2017
Functional programming is the most extreme programming
Scala - The Simple Parts, SFScala presentation
Polyglot and Functional Programming (OSCON 2012)
Stay fresh

More from Renzo Borgatti (10)

PDF
Clojure beasts-euroclj-2014
PDF
Introduzione a macruby
PDF
MacRuby For Ruby Developers
PDF
Lavorare Da Remoto
PDF
You Say Tomato I Say Pomodoro
PDF
Agile Pomodoro Development
PDF
Writing Apps with HotCocoa and MacRuby
PDF
Introduction to Agile Development with Scrum
PDF
You say Tomato, I say Pomodoro
PDF
Ruby BDD for Java
Clojure beasts-euroclj-2014
Introduzione a macruby
MacRuby For Ruby Developers
Lavorare Da Remoto
You Say Tomato I Say Pomodoro
Agile Pomodoro Development
Writing Apps with HotCocoa and MacRuby
Introduction to Agile Development with Scrum
You say Tomato, I say Pomodoro
Ruby BDD for Java

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
KodekX | Application Modernization Development
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Approach and Philosophy of On baking technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Machine learning based COVID-19 study performance prediction
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
sap open course for s4hana steps from ECC to s4
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Review of recent advances in non-invasive hemoglobin estimation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25 Week I
Dropbox Q2 2025 Financial Results & Investor Presentation
Per capita expenditure prediction using model stacking based on satellite ima...
Advanced methodologies resolving dimensionality complications for autism neur...
KodekX | Application Modernization Development
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Approach and Philosophy of On baking technology
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation_ Review paper, used for researhc scholars
Spectral efficient network and resource selection model in 5G networks
Machine learning based COVID-19 study performance prediction
Network Security Unit 5.pdf for BCA BBA.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Digital-Transformation-Roadmap-for-Companies.pptx

Introduction to Clojure

  • 1. Introduction To Clojure BBC lunch & learn, July 18th 2012 Renzo Borgatti, Developer in Test, A/V Team Welcome to this introduction to the Clojure language. Clojure had a lot of attraction lately as well other well known languages based on the functional paradigm like Erlang or inspired from the functional paradigm like Scala. There is definitely a reason for the return of the functional paradigm nowadays that we are going to explain briefly in this talk. My name is Renzo Borgatti, blah blah
  • 2. the functional re-emergence roots in λ-calculus 1930 re-discovered with Lisp 1958 The functional paradigm has its root in the Lambda calculus, a method for notations and manipulation of mathematical functions introduced by Alonso Church around 1930. Lambda calculus was then rediscovered as a versatile programming tool by McCarthy in 1958 when Lisp was introduced as a programming language able to deal with mathematical notation.
  • 3. Moore’s failure for cpu clock but cpu density growing fast software is the new bottleneck need to design for concurrency Moore’s law recently failed on one of its axis. CPU speed is not doubling or tripling every year anymore. It used to be the case in the late ’90. But the demand of computing power is growing as usual. Hardware manufacturer resorted to other means to increase power, such as transistor density. Right now is not uncommon to see cheap laptops sold with 4 cpu cores out of the box. Change on chip density requires a change in software scalability. Software must be written for concurrency to take advantage of multi-core architectures.
  • 4. OOP encapsulates state changes overwrite state state has multiple observers concurrency requires locking locking is complicated Object Oriented Programming confines state using specific language constructs like classes. The Program flows as a series of state changes. When state needs concurrent access it must be protected using locks because there could be multiple computations going on at the same time. A change on the state delete previous values and the history is lost The problem is that “identity” and “values” are overlapping A clear example is a date object. A date is created to hold a value, maybe the the hottest day of the year. If there is a new record this year, that is the new hottest day. But what about the previous one? Why it should be completely replaced by changing the date and removing the information from the system? What about all the threads that were observing the value producing metrics for the old date? Should that information being lost by changing the date instance or should each thread just keep going observing the old value until they decide otherwise? State based languages are hard to understand and to debug. Looking at some method, chances are you can’t be sure until runtime about what that method is supposed to behave in certain condition. Sometimes even at runtime the portion of state influencing the computation is so big that is impossible to handle correctly. Concurrency based on locks is complicated, generating deadlock conditions and all sort of synchronisation issues.
  • 5. Clojure, Scala, F#, Erlang... focus on immutability semantic for changing values “new” model for concurrency Hence why the resurgence of the “old” and “academic” functional model. Why not Lisp or Haskell? Clojure Scala and F# all have in common the fact that they are hosted, so interoperability with known languages it’s easy. Erlang is a special case of non-hosted functional language that became popular. Erlang is very focused on high availability and performs great in that kind of environments.
  • 6. A dynamically-typed jvm-based Lisp dialect Rich Hickey 2007 now 1.4 What about Clojure in specific? Clojure is a relatively young programming language based on Lisp but running on the JVM. It comes out from the frustration of Rich Hickey developing highly concurrent systems as a Java and .NET consultant. Rich Hickey developed dotLisp for the .NET environment before Clojure. He spent then 2.5 years designing and implementing Clojure. Clojure was officially announced in 2007.
  • 7. interactive hosted dynamic it’s a Lisp functional concurrent These are the main Clojure design principles. Clojure is a “consenting adults” language. It sits someway between the functional pureness of Haskell and the lazy-evaluate-everything of Scheme. Checking for functions that aren’t pure in Clojure is technically possible, but that will make more than half of the JDK or CLR unusable.
  • 8. interactive REPL read-eval-print loop suitable for exploration introspection capabilities fast development loop demo Show off REPL in action: - repl special variables *1 *2 *3 etc - the content of (pst) after an exception - doc searching and print sources - (find-doc “some”) - (use ‘clojure.repl) (source func)
  • 9. hosted built with Java interop in mind use Java directly no wrappers lots of syntatic sugar demo - java interop demo - (filter #(re-seq #"pper" (.getName %)) (seq (.getMethods String))) - (import 'java.util.Date) (def now (Date.)) - (.. "" getClass getMethods)
  • 10. dynamic less ceremony: speed concise: where’s my code ~1:1 ratio sudocode real code Clojure is dynamic in two ways. It’s dynamically typed, so it doesn’t specify types. Explicit typing would be more useful for a language that at compile time can check if the current functions are producing side effects and issue warnings. For Clojure dynamic typing means to be more concise and more flexible. Second, Clojure it’s dynamic in the way programmers can approach development with it: firing up a REPL, test live code that gets automatically re-evaluated (when needed) and tweak the main program on the go. Less ceremony means speed: less code to type, less potential bugs, code is more readable. Conciseness measures the quantity of code needed to express a “task” in the language. When the language is concise it’s easier for the programmer to focus on business logic. Potentially a 1:1 ratio between sudocode and the actual code would be ideal.
  • 11. dynamic by the way, not this kind... ...of expressiveness! That’s the APL one liner for the game of life. http://catpad.net/michael/apl/
  • 12. dynamic but instead of something like This is the isBlank static method in StringUtils from Apache commons. I have a quiz for you. I removed the name of the method. By reading the java and the clojure version of the same behaviour, could you tell what the method is actually doing? If yes, was the Java or the Clojure version more helpful?
  • 13. It’s a Lisp homoiconic data as code powerful macro programming define new syntax demo In Clojure everything that the compiler sees are just data structure although there is some syntactic sugar to make it easier to program. But before the compiler there is a Reader in Clojure which transforms the textual input into data structures. Homoiconic means just that, that everything is a data structure. Why this is important? Because the syntax is much simpler and more abstract constructs can be built in term of a bunch of primitives. It also make it easier for macro programming. Macros are special constructs which are interpreted by the reader and will influence the final output which is going to the compiler. With Macros you can effectively extend the language. Clojure “when”, “for” or syntax like the arrow operator “->” are effectively macros. (macroexpand '(when (= "a" "a") (def renzo ", renzo") (str "this is also true" renzo))) (macroexpand '(for [x (range 10)] (str x)))
  • 14. functional focus on immutability side-effects free functions caching and laziness “consenting adults” pureness Finally, Clojure is functional. It should be already clear at this point of the presentation. Clojure main data structures are immutable, requiring a specific semantic to be altered. Being functional means that the output of a function can only be influenced by its inputs. The parameters must hence be immutable. If they were mutable then the function would have a chance to be impure by altering them. When a function is pure there are no side effects so it is producing repeatable results which are independent from the state of the system. Repeatable means caching can be implemented easily. Laziness follows because there is no need to “render” the result of a function until it’s actually needed. Laziness means more optimisation opportunities for the compiler. Clojure always allows you to skip all of that and introduce side effects all around. It does not have the assignment operator though.
  • 15. concurrent immutable core data structures constrained change semantic atom, ref, agent, var demo Clojure has been built with a focus on concurrency. Main data structures are immutable requiring special semantic to be altered. There are four types of clojure construct to alter immutable structures. Atoms are simple CAS (compare and swap) semantic. You create an atom and then you can change it by just calling swap! on it passing the function that should alter the content of the atom. The swap! will succeed or not, based on a comparison with the current value in the atom. If the value is changed by another thread in the middle, the swap! will be attempted again over the new value. Needless to say, the altering function needs to be side effects free. Atoms cannot coordinate over multiple values. You need Refs for that. A ref is similar to a database transaction. You need to open a transaction before attempting to change any of the Refs. Transactions can be attempt an arbitrary number of times. Agents are similar to Atoms in the sense that they are uncoordinated. But an action sent to an Agent will be executed at some later point in time, on a thread pool. Vars is thread-local state that can be altered by using the (binding) form. They can be used where too many repeating parameters are unpractical (like Java).
  • 16. Clojure is not a replacement not just for list comprehension radical approach steeper learning curve what about all those parenthesis? Clojure has not been built to be a replacement for Java as other languages. It was built with imperative and state based languages drawbacks to solve the problem entirely. Another thing that is valid for all functionally inspired languages is that the functional paradigm is not about having functions as variables that can be sent around and used on collections. Ruby and Python aren’t certainly functional but they are heavily based on closures (aka lambdas). Scala is more functional in this respect but it allows assignment and support object orientation with instance variables that are clearly used to obtain side effects. If you come from another paradigm and usually programming in Java the Clojure learning curve will be probably steeper than Groovy or Scala. Java people tend to try to match parenthesis as soon as they see them. Brackets mostly delimit scope and give structure to the code. Lispers don’t need to match parenthesis.
  • 17. Who is using Clojure? The always evolving lists: http://dev.clojure.org/display/community/Clojure+Success+Stories http://www.quora.com/Whos-using-Clojure-in-production
  • 18. Clojure is a good hiring tool attract smart people diversify company mindset There is an higher probability to attract the Lisp community with Clojure than Scala. The Lisp community includes a very fine selected crowd of people who must have been in deeply love with their language if they remained outside the mainstream languages for something like half a century! Apart from jokes, the average mathematical and algorithmic background of the Lisp community is very high and a nice addition for you team. An useful link: the london clojurians jobs page (requires to join the mailing list): - https://groups.google.com/forum/?fromgroups#!forum/london-clojurian-jobs
  • 19. Scala Clojure type system change semantic models complicated type system clever sequences actor concurrency no objects good java interops harder to recruit friendly java syntax top-notch java interops object/functional steeper learning curve Lisp community The not-definitive Scala to Clojure comparison chart in no specific order of priority. The two languages have completely different philosophies but the impression is that at the end they have more in common than expected. There are hiring and people factors to consider when choosing one or the other. Clojure is a radical approach that refuses objects as the main tool to model the world, especially a concurrent world. Scala embraces both styles and let object oriented developers depart from the paradigm when needed. The choice between the two language is almost impossible to make outside a specific context. They both have pro and cons that compensate each other on an absolute scale. What should not happen in both cases is that you choose the language because you can “send methods to collections and around”. There is much more about the functional paradigm that has nothing to do with closures.
  • 20. General resources the main clojure website: http://www.clojure.org easily browsable documentation: http://clojuredocs.org the london clojure dojo and group: http://londonclojurians.org who is using Clojure? http://dev.clojure.org/display/community/Clojure+Success+Stories paper introducing lamda calculus to programmers: http://www.cs.bham.ac.uk/~axj/pub/papers/lambda-calculus.pdf introducing clojure in the organization: http://blog.jayfields.com/2012/01/lessons-learned-while-introducing-new.html
  • 21. BBC resources The BBC clojure weekly dojo, every Thu 12:30 van gogh: https://confluence.dev.bbc.co.uk/display/~renzo.borgatti@bbc.co.uk/clojure-ug BBC Clojure forge mailing list: https://lists.forge.bbc.co.uk/mailman/listinfo/clojure BBC Clojure forge IRC channel: #clojure
  • 22. Talk Slides PDF available here: https://confluence.dev.bbc.co.uk/display/~renzo.borgatti@bbc.co.uk/clojure-ug Please rate my talk: sdfdfd Video will be available soon
  • 25. if Java had closures today (they’ll be in Java 8) would you still consider Scala or Groovy? Is it still worth learning a new language for that only?
  • 26. (let [audience people-present-today] (map #(str “THANK YOU, ” %) audience))