- imperative
- S-Expression
- anti object-oriented
programming language
- on JVM
- on JavaScript
(prn "hello world!")
(def hello-world "Bonjour!")
(defn -main []
(prn hello-world))
- JavaScript
console.log((x + 10) * 2);
- Clojure
(prn (* (+ x 10) 2))
- Or
(prn (-> (+ x 10) (* 2)))
(fn [x]
(* (+ x 10) 2))
- Or with macro
#(* (+ % 10) 2)
-
Symbol
:abc
-
Vector
[1 2 3 4 5]
["a" :b \c]
- Map (dictionary; hash)
{:a "hi" :b []}
easy to
- read
- macro / immutability / naming
- write
- syntax
- make it concurrent
- immutability / future / STM
- defn
- prn
- cons/conj
(cons 1 [2 3]) ;=> [1 2 3]
(conj [2 3] 1) ;=> [2 3 1]
(if a
b
c)
(if a
(do
b1
b2)
c)
(when a
b1
c2)
comment
#_
(prn #_(+ 2 (* 3 4)) 999)
-
Clojure is good partly because it's on JVM
-
Clojure is terribly bad because it's on JVM
- Java
x.m(a, b);
C.f(x);
- Clojure
(.m x a b)
(C/f x)
-
slow to start, fast to run
-
faster to start, slower to run compare to Scala
Ruby (2.1.0)
- hello world: 0.02sec
- fib(40): 15.58sec
Clojure (1.5.1)
- hello world: 1.19sec
- fib(40): 4.84sec
Yes!
-
Leiningen (build tool)
-
clojars.org (library; ecosystem)
-
tools that depend on libraries for java
- No continuations (call/cc)
- No automatic tail call optimization
- No alternative string literals
- (No user-defined reader macro)
-
Clojure
-
made by Rich Hickey since 2007
-
google "tryclojure" to run some code even without installing clojure