Clojure: A New Lisp with Excellent Concurrency Support and Tight Java Integration
1. Clojure
A new Lisp
with excellent concurrency support
and tight Java integration
2. Why Lisp?
Simple – easy to learn
Expressive – say a lot with a little
Flexible – becomes what you want
3. Why Clojure?
Advantages of Lisp, plus...
Works with your existing Java code
Uses your favorite Java libraries
Makes concurrency easy
4. What made Lisp different
(Paul Graham)
1) Conditionals 6) Programs composed
2) Function type of expressions
3) Recursion 7) A symbol type
4) Variables as pointers 8) Code as data
5) Garbage collection 9) Reader, compiler,
and evaluator
available to program
5. Simple Data Compound Data
h “house”
74 [1 2 3 4]
true (true false)
:firstname {:firstname “Eric” :last
7/8 name “Lavigne”}
5.4 #{“house” “office”
“museum”}
nil
10. HigherOrder Functions
Functions can be used as input to other functions.
(map addsix [0 4 10]) => (6 10 16)
(def sum
(fn [x] (reduce + 0 x)))
(def product
(fn [x] (reduce * 1 x)))
11. Macros
Tired of patterns like this?
(def addsix (fn [x] (+ x 6)))
The defn macro in the standard library allows you
to write this:
(defn addsix [x] (+ x 6))
Patterns are a sign that it's time for a function or
macro. Don't repeat yourself :)
16. How It Will Be Used
package aotexample;
public class TestMultipliers {
public static void main(String[] args) {
System.out.println("Result of Java version is "
+ new JavaMultiplier(3).multiply(2));
System.out.println("Result of Clojure version is "
+ new ClojureMultiplier(new Integer(3)).multiply(2));
}
}
17. Java Version
package aotexample;
import java.io.Serializable;
public class JavaMultiplier implements Serializable {
private Integer a;
public JavaMultiplier(Integer a) {
this.a = a;
}
public Integer multiply(Integer b) {
return a * b;
}
}