5. Problems with Java as a language
lack of functional programming (FP) support
More FP! (OOP and static typing are not necessary)
verbose syntax
More simplicity!
lack of exibility/extensibility
More freedom!
6. JVM language comparison
from my own point of view
factor Java Groovy Scala Kotlin Clojure
FP support × △ ◯ △ ◯
simplicity × ◯ △ ◯ ◎
exibility × ◯ ◯ ◯ ◎
7. Using Clojure,
we can say goodbye to Java as a language!!
Adieu, Java !
Now we have to say farewell to you, Java (;_;)/~~~
9. Origin of the name Clojure
Clojure is pronounced exactly like closure, where
the s/j has the zh sound as in azure, pleasure etc.
The name was chosen to be unique. I wanted to
involve c (c#), l (lisp) and j (java).
Once I came up with Clojure, given the pun on
closure, the available domains and vast emptiness
of the googlespace, it was an easy decision.
― Rich Hickey, creator of Clojure
cf. meaning and pronunciation of Clojure
10. Clojure /ˈkloʊʒɚ/
* NOT /ˈkloʊd͡ʒɚ/
element meaning
/ˈkloʊʒɚ/ closure, functional programming
C C#(.NET) as a platform, .NET language
l Lisp dialect
j Java as a platform, JVM language
11. 1. Clojure as a FP language
2. Clojure as a Lisp dialect
3. Clojure as a JVM language
19. S-expressions
(f a b c ...)
f: function, macro, special form
a, b, c, ...: arguments
cf. Java
f(a, b, c, ...)
20. Even a function/method de nition
// Java
public void greet(String name) {
System.out.println("Bonjour, " + name + " !");
}
is an S-expression.
;; Clojure
(defn greet [name]
(println (str "Bonjour, " name " !")))
21. Even namespace/package declaration and imports
// Java
package demo_app;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
are S-expressions.
;; Clojure
(ns demo-app.core
(:import (java.io IOException)
(java.util ArrayList List)))
25. BTW,
defn used for function de nition
user=> (macroexpand
#_=> '(defn greet [name]
#_=> (println (str "Bonjour, " name " !"))))
(def greet (clojure.core/fn ([name] (println (str "Bonjour, " name " !")))))
is a macro composed of def, fn special forms.
26. Hard to handle a lot of parentheses?
⇒Lisp-editing plugins make it very comfortable
The Animated Guide to Paredit
Parinfer - simpler Lisp editing
28. Compiling to Java class les
executable as a jar
$ lein new app demo-app
Generating a project called demo-app based on the 'app' template.
$ cd demo-app/
$ lein uberjar
Compiling demo-app.core
Created /Users/lagenorhynchus/code/demo-app/target/uberjar/demo-app-0.1.0-SNAPSHOT.jar
Created /Users/lagenorhynchus/code/demo-app/target/uberjar/demo-app-0.1.0-SNAPSHOT-standalone.jar
$ java -jar target/uberjar/demo-app-0.1.0-SNAPSHOT-standalone.jar
Hello, World!
29. Calling Java methods
static methods
// Java
Integer.parseInt("123")
;; Clojure
(Integer/parseInt "123")
instance methods
// Java
"a b c".split("s")
;; Clojure
(.split "a b c" "s")