A taste of Clojure at Lightspeed

John Stevenson


Overview of Clojure

A modern dialect of LISP

Functional paradigm

Dynamic typing

Created to run on the Java Virtual Machine

  • everything is bytecode in the end

Functional programming

A relatively pure approach

  • encourages minimum state change

Everything is an expression (data & functions)

Everything is a data structure (a list)

Uses prefix notation

Organise expressions in namespaces (like Java packages)

Runs on the Java Virtual Machine

Clojure is compiled into bytecode before running

Runs on other environments

ClojureScript in the browser

Clojure on Microsoft CLR

Getting Started with Clojure

Install a Java development kit

Use OpenJDK or Oracle Java Standard Edition

Check its installed using the command:

javac -version

Install Leiningen

Leiningen is a build automation tool for Clojure

  • think maven without the pain

Download the install script from leiningen.org

Check leiningen is working with the command:

lein help

Clojure installed via build tools

Clojure is a jar file

Use leiningen to pull it into your projects as a dependency

  • or maven if you like that sort of thing

Learning Clojure with the REPL

A REPL for learning / experimenting

Clojure has a run time environment called the REPL

  • use to evaluate expressions instantly
  • load in code from files and test functions
  • add data & behaviour without affecting projects or libraries
  • REPL driven development

Start a REPL

Use Leiningen to start a new REPL:

lein repl

Enter expressions

Start with some simple expressions

(+ 1 2 3 4)

(str "Hello" ", " "Clojure World")

(def map-of-me 
     {:name "John" :surname "Stevenson" 
      :age 21 
      :honesty-rating "poor" 
      :fav-authors ["Douglas Adams" "Terry Pratchett"]}

Creating your first Clojure app

Create your app with Leiningen

lein new my-app
lein new template my-app

Version your app with Git

Version a clojure project as with any other language.

Don't version control external libraries, Leiningen takes care of that for you.

Github has a gitignore file for Clojure with Leiningen

Create a Clojure app on Heroku

  • Leiningen can use a template for an Heroku project
  • connects your local repo to Heroku
  • creates a unique URL for your app

– you can specify your own unique name

lein new heroku my-scalable-webapp
heroku create unique-subdomain-name

Running your Clojure app

Use Leiningen to run your app

lein run
  • Use Leiningen to run a REPL, then load in your app
lein repl
(use 'namespace.name)
  • Run as a Java jar file
java -jar my-app.jar 
<or use maven, gradle, etc.>

Slide with background image


  • bulletpoint
  • dont go crazy

Sub-slide - srolls vertically from slide above

Some source code using hightlits.js

(def clojure-devs "love brackets")

Slide with code

git init

Slide with Colour - overriding the theme

I love red.

Hightliht text as a fragment of the slide

Fragments in Reveal.js

Press the "Down" key on the page or the down arrow to trigger fragments

  • Create
  • Fragment
  • At Ease

Fragment captions

#+ATTR_REVEAL: :frag
   * Create
   * Fragment
   * At Ease

Reveal.js Can Alert

Change slide style to wake up the sleepy audience.