SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
From Java To Clojure
- Adieu Java -
Self-introduction
/laʒenɔʁɛ̃k/lagénorhynque
(defprofile lagénorhynque
:name "Kent OHASHI"
:account @lagenorhynque
:company "Opt, Inc."
:languages [Clojure Haskell Python Scala
English français Deutsch русский]
:interests [programming language-learning mathematics])
Lisp × Java
Java as a language
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!
JVM language comparison
from my own point of view
factor Java Groovy Scala Kotlin Clojure
FP support × △ ◯ △ ◯
simplicity × ◯ △ ◯ ◎
exibility × ◯ ◯ ◯ ◎
Using Clojure,
we can say goodbye to Java as a language!!
Adieu, Java !
Now we have to say farewell to you, Java (;_;)/~~~
What is Clojure?
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
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
1. Clojure as a FP language
2. Clojure as a Lisp dialect
3. Clojure as a JVM language
Clojure as a FP language
Immutable List, Vector, Map, Set, etc.
user=> '(1 2 3)
(1 2 3)
user=> [1 2 3]
[1 2 3]
user=> {:a 1 :b 2 :c 3}
{:a 1, :b 2, :c 3}
user=> #{1 2 3}
#{1 3 2}
Higher-order functions
(filter, map, reduce, etc.)
user=> (def xs [1 2 3])
#'user/xs
user=> (filter odd? xs)
(1 3)
user=> (map #(* % %) xs)
(1 4 9)
user=> (reduce + 0 xs)
6
user=> (reduce + 0 (map #(* % %) (filter odd? xs)))
10
user=> (->> xs
#_=> (filter odd?)
#_=> (map #(* % %))
#_=> (reduce + 0))
10
BTW,
#( ) is
#(* % %)
↓↓↓
(fn [x] (* x x))
a reader macro equivalent as above.
BTW,
->> is
(->> a
(f x)
(g y)
(h z))
↓↓↓
(h z (g y (f x a)))
a macro (a kind of threading macros) expanded as above.
Lazy sequences
user=> (def nats (iterate inc 0))
#'user/nats
user=> (take 10 nats)
(0 1 2 3 4 5 6 7 8 9)
user=> (take-while #(< % 10) nats)
(0 1 2 3 4 5 6 7 8 9)
Clojure as a Lisp dialect
S-expressions
(f a b c ...)
f: function, macro, special form
a, b, c, ...: arguments
cf. Java
f(a, b, c, ...)
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 " !")))
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)))
first(≒ car), rest(≒ cdr), cons, ...
user=> (def xs [1 2 3])
#'user/xs
user=> (first xs)
1
user=> (rest xs)
(2 3)
user=> (cons 0 xs)
(0 1 2 3)
S-expression code can be treated as data
(code as data; )homoiconicity
user=> (first '(def xs [1 2 3]))
def
user=> (rest '(def xs [1 2 3]))
(xs [1 2 3])
user=> (cons 'def '(xs [1 2 3]))
(def xs [1 2 3])
user=> (eval (cons 'def '(xs [1 2 3])))
#'user/xs
Lisp macros
powerful compile-time metaprogramming facility
user=> (defmacro unless ; just a reimplementation of clojure.core/if-not macro
#_=> ([test then]
#_=> `(unless ~test ~then nil))
#_=> ([test then else]
#_=> `(if (not ~test)
#_=> ~then
#_=> ~else)))
#'user/unless
user=> (unless (= 1 2) :ok)
:ok
user=> (macroexpand '(unless (= 1 2) :ok))
(if (clojure.core/not (= 1 2)) :ok nil)
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.
Hard to handle a lot of parentheses?
⇒Lisp-editing plugins make it very comfortable
The Animated Guide to Paredit
Parinfer - simpler Lisp editing
Clojure as a JVM language
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!
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")
destructive initialisation/setting
// Java
java.util.Map<String, Integer> m = new java.util.HashMap<>();
m.put("a", 1);
m.put("b", 2);
m.put("c", 3);
return m;
;; Clojure
(doto (java.util.HashMap.)
(.put "a" 1)
(.put "b" 2)
(.put "c" 3))
method chaining
// Java
new StringBuilder()
.append("a")
.append("b")
.append("c")
.toString()
;; Clojure
(.. (StringBuilder.)
(append "a")
(append "b")
(append "c")
toString)
;; or
(-> (StringBuilder.)
(.append "a")
(.append "b")
(.append "c")
.toString)
Interoperating with Java collection API
Java collection → Clojure function
user=> (def xs (doto (java.util.ArrayList.)
#_=> (.add 1)
#_=> (.add 2)
#_=> (.add 3)))
#'user/xs
user=> (class xs)
java.util.ArrayList
user=> xs
[1 2 3]
user=> (map inc xs)
(2 3 4)
Clojure collection → Java method
user=> (def xs [1 2 3 4 5])
#'user/xs
user=> (class xs)
clojure.lang.PersistentVector
user=> (instance? java.util.List xs)
true
user=> (.subList xs 1 4)
[2 3 4]
cf. usage example of Google Sheets API (Java)
// Java
public Integer duplicateWorksheet(Sheets sheets, String spreadsheetId, Integer worksheetId, Strin
List<Request> reqs = Arrays.asList(
new Request().setDuplicateSheet(
new DuplicateSheetRequest().setSourceSheetId(worksheetId)
.setNewSheetName(worksheetName)
.setInsertSheetIndex(1)
)
);
return executeUpdate(sheets, spreadsheetId, worksheetId, reqs)
.getReplies()
.get(0)
.getDuplicateSheet()
.getProperties()
.getSheetId();
}
;; Clojure
(defn duplicate-worksheet [sheets spreadsheet-id worksheet-id worksheet-name]
(let [reqs [(-> (Request.)
(.setDuplicateSheet
(-> (DuplicateSheetRequest.)
(.setSourceSheetId worksheet-id)
(.setNewSheetName worksheet-name)
(.setInsertSheetIndex (int 1)))))]]
(-> (execute-update sheets spreadsheet-id worksheet-id reqs)
.getReplies
first
.getDuplicateSheet
.getProperties
.getSheetId)))
Furthermore,
core.async
transducers
clojure.spec
ClojureScript
etc.
If you use Clojure,
with the power of FP, Lisp and Java
you can program more simply, more freely!!
Vive les S-expressions !
Long live S-expressions!
Further Reading
: Clojure o cial site
: Clojure build tool
: Clojure build tool
: Clojure online REPL
: ClojureScript online REPL
Chapter 7: Clojure
Clojure
Leiningen
Boot
Try Clojure
Replumb REPL
Seven Languages in Seven Weeks
Programming Clojure (2nd edition)

Mais conteúdo relacionado

Mais procurados

ekb.py - Python VS ...
ekb.py - Python VS ...ekb.py - Python VS ...
ekb.py - Python VS ...it-people
 
Practical REPL-driven Development with Clojure
Practical REPL-driven Development with ClojurePractical REPL-driven Development with Clojure
Practical REPL-driven Development with ClojureKent Ohashi
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objectsjulien pauli
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?FITC
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersLin Yo-An
 
JRuby @ Boulder Ruby
JRuby @ Boulder RubyJRuby @ Boulder Ruby
JRuby @ Boulder RubyNick Sieger
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaPatrick Allaert
 
Swiftの関数型っぽい部分
Swiftの関数型っぽい部分Swiftの関数型っぽい部分
Swiftの関数型っぽい部分bob_is_strange
 
Domain Specific Languages In Scala Duse3
Domain Specific Languages In Scala Duse3Domain Specific Languages In Scala Duse3
Domain Specific Languages In Scala Duse3Peter Maas
 
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPGuilherme Blanco
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueLearn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueJames Thompson
 
Red Flags in Programming
Red Flags in ProgrammingRed Flags in Programming
Red Flags in ProgrammingxSawyer
 

Mais procurados (20)

ekb.py - Python VS ...
ekb.py - Python VS ...ekb.py - Python VS ...
ekb.py - Python VS ...
 
Practical REPL-driven Development with Clojure
Practical REPL-driven Development with ClojurePractical REPL-driven Development with Clojure
Practical REPL-driven Development with Clojure
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objects
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
 
JRuby @ Boulder Ruby
JRuby @ Boulder RubyJRuby @ Boulder Ruby
JRuby @ Boulder Ruby
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 Verona
 
Swiftの関数型っぽい部分
Swiftの関数型っぽい部分Swiftの関数型っぽい部分
Swiftの関数型っぽい部分
 
Domain Specific Languages In Scala Duse3
Domain Specific Languages In Scala Duse3Domain Specific Languages In Scala Duse3
Domain Specific Languages In Scala Duse3
 
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHPIPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
 
node ffi
node ffinode ffi
node ffi
 
Javascript status 2016
Javascript status 2016Javascript status 2016
Javascript status 2016
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
JavaScript Looping Statements
JavaScript Looping StatementsJavaScript Looping Statements
JavaScript Looping Statements
 
Rakudo
RakudoRakudo
Rakudo
 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueLearn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a Rescue
 
Red Flags in Programming
Red Flags in ProgrammingRed Flags in Programming
Red Flags in Programming
 
Rust言語紹介
Rust言語紹介Rust言語紹介
Rust言語紹介
 

Destaque

Practical Phonetics (実践音声学)
Practical Phonetics (実践音声学)Practical Phonetics (実践音声学)
Practical Phonetics (実践音声学)Kent Ohashi
 
From Java To Clojure
From Java To ClojureFrom Java To Clojure
From Java To ClojureKent Ohashi
 
おいしいLisp
おいしいLispおいしいLisp
おいしいLispKent Ohashi
 
Agile2011-Agile Education by Object Game
Agile2011-Agile Education by Object Game Agile2011-Agile Education by Object Game
Agile2011-Agile Education by Object Game Tsuyoshi Ushio
 
Clojure座談会 #1 LT 独自コレクションを定義しよう
Clojure座談会 #1 LT 独自コレクションを定義しようClojure座談会 #1 LT 独自コレクションを定義しよう
Clojure座談会 #1 LT 独自コレクションを定義しようKeisuke Fukuda
 
Rデモ01_はじめの一歩2016
Rデモ01_はじめの一歩2016Rデモ01_はじめの一歩2016
Rデモ01_はじめの一歩2016wada, kazumi
 
Rプログラミング01 はじめの一歩
Rプログラミング01 はじめの一歩Rプログラミング01 はじめの一歩
Rプログラミング01 はじめの一歩wada, kazumi
 
ロジカル・シンキング & システム設計・プログラミングについて
ロジカル・シンキング & システム設計・プログラミングについてロジカル・シンキング & システム設計・プログラミングについて
ロジカル・シンキング & システム設計・プログラミングについてDai Saito
 
Rデモ02_入出力編2016
Rデモ02_入出力編2016Rデモ02_入出力編2016
Rデモ02_入出力編2016wada, kazumi
 
Rデモ03_データ分析編2016
Rデモ03_データ分析編2016Rデモ03_データ分析編2016
Rデモ03_データ分析編2016wada, kazumi
 
Rプログラミング02 データ入出力編
Rプログラミング02 データ入出力編Rプログラミング02 データ入出力編
Rプログラミング02 データ入出力編wada, kazumi
 
WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.
WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.
WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.Oliver Kriska
 
HTTP/2 in nginx(2016/3/11 社内勉強会)
HTTP/2 in nginx(2016/3/11 社内勉強会)HTTP/2 in nginx(2016/3/11 社内勉強会)
HTTP/2 in nginx(2016/3/11 社内勉強会)Yoko TAMADA
 
Rプログラミング03 データ分析編
Rプログラミング03 データ分析編Rプログラミング03 データ分析編
Rプログラミング03 データ分析編wada, kazumi
 
Embracing Clojure: a journey into Clojure adoption
Embracing Clojure: a journey into Clojure adoptionEmbracing Clojure: a journey into Clojure adoption
Embracing Clojure: a journey into Clojure adoptionLuca Grulla
 
穆黎森:Interactive batch query at scale
穆黎森:Interactive batch query at scale穆黎森:Interactive batch query at scale
穆黎森:Interactive batch query at scalehdhappy001
 

Destaque (20)

Practical Phonetics (実践音声学)
Practical Phonetics (実践音声学)Practical Phonetics (実践音声学)
Practical Phonetics (実践音声学)
 
From Java To Clojure
From Java To ClojureFrom Java To Clojure
From Java To Clojure
 
Functional Way
Functional WayFunctional Way
Functional Way
 
MP in Haskell
MP in HaskellMP in Haskell
MP in Haskell
 
おいしいLisp
おいしいLispおいしいLisp
おいしいLisp
 
MP in Scala
MP in ScalaMP in Scala
MP in Scala
 
Agile2011-Agile Education by Object Game
Agile2011-Agile Education by Object Game Agile2011-Agile Education by Object Game
Agile2011-Agile Education by Object Game
 
Clojure座談会 #1 LT 独自コレクションを定義しよう
Clojure座談会 #1 LT 独自コレクションを定義しようClojure座談会 #1 LT 独自コレクションを定義しよう
Clojure座談会 #1 LT 独自コレクションを定義しよう
 
Rデモ01_はじめの一歩2016
Rデモ01_はじめの一歩2016Rデモ01_はじめの一歩2016
Rデモ01_はじめの一歩2016
 
Rプログラミング01 はじめの一歩
Rプログラミング01 はじめの一歩Rプログラミング01 はじめの一歩
Rプログラミング01 はじめの一歩
 
ロジカル・シンキング & システム設計・プログラミングについて
ロジカル・シンキング & システム設計・プログラミングについてロジカル・シンキング & システム設計・プログラミングについて
ロジカル・シンキング & システム設計・プログラミングについて
 
Rデモ02_入出力編2016
Rデモ02_入出力編2016Rデモ02_入出力編2016
Rデモ02_入出力編2016
 
Rデモ03_データ分析編2016
Rデモ03_データ分析編2016Rデモ03_データ分析編2016
Rデモ03_データ分析編2016
 
Rプログラミング02 データ入出力編
Rプログラミング02 データ入出力編Rプログラミング02 データ入出力編
Rプログラミング02 データ入出力編
 
WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.
WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.
WebUp Feb 2017 - How (not) to get lost in bigger Ruby on Rails project.
 
HTTP/2 in nginx(2016/3/11 社内勉強会)
HTTP/2 in nginx(2016/3/11 社内勉強会)HTTP/2 in nginx(2016/3/11 社内勉強会)
HTTP/2 in nginx(2016/3/11 社内勉強会)
 
Rプログラミング03 データ分析編
Rプログラミング03 データ分析編Rプログラミング03 データ分析編
Rプログラミング03 データ分析編
 
Embracing Clojure: a journey into Clojure adoption
Embracing Clojure: a journey into Clojure adoptionEmbracing Clojure: a journey into Clojure adoption
Embracing Clojure: a journey into Clojure adoption
 
Codemash-Clojure.pdf
Codemash-Clojure.pdfCodemash-Clojure.pdf
Codemash-Clojure.pdf
 
穆黎森:Interactive batch query at scale
穆黎森:Interactive batch query at scale穆黎森:Interactive batch query at scale
穆黎森:Interactive batch query at scale
 

Semelhante a From Java To Clojure (English version)

Java Intro
Java IntroJava Intro
Java Introbackdoor
 
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Howard Lewis Ship
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015Michiel Borkent
 
Intro to scala
Intro to scalaIntro to scala
Intro to scalaJoe Zulli
 
Clojure: Functional Concurrency for the JVM (presented at OSCON)
Clojure: Functional Concurrency for the JVM (presented at OSCON)Clojure: Functional Concurrency for the JVM (presented at OSCON)
Clojure: Functional Concurrency for the JVM (presented at OSCON)Howard Lewis Ship
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaOstap Andrusiv
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMsunng87
 
ClojurianからみたElixir
ClojurianからみたElixirClojurianからみたElixir
ClojurianからみたElixirKent Ohashi
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with ClojureJohn Stevenson
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Introthnetos
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
 

Semelhante a From Java To Clojure (English version) (20)

Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Java Intro
Java IntroJava Intro
Java Intro
 
JavaFXScript
JavaFXScriptJavaFXScript
JavaFXScript
 
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
Clojure: Functional Concurrency for the JVM (presented at Open Source Bridge)
 
Hello java
Hello java  Hello java
Hello java
 
Hello java
Hello java   Hello java
Hello java
 
Hello Java-First Level
Hello Java-First LevelHello Java-First Level
Hello Java-First Level
 
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
Clojure: Functional Concurrency for the JVM (presented at OSCON)
Clojure: Functional Concurrency for the JVM (presented at OSCON)Clojure: Functional Concurrency for the JVM (presented at OSCON)
Clojure: Functional Concurrency for the JVM (presented at OSCON)
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with Scala
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVM
 
ClojurianからみたElixir
ClojurianからみたElixirClojurianからみたElixir
ClojurianからみたElixir
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Groovy
GroovyGroovy
Groovy
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 

Mais de Kent Ohashi

インターフェース定義言語から学ぶモダンなWeb API方式: REST, GraphQL, gRPC
インターフェース定義言語から学ぶモダンなWeb API方式: REST, GraphQL, gRPCインターフェース定義言語から学ぶモダンなWeb API方式: REST, GraphQL, gRPC
インターフェース定義言語から学ぶモダンなWeb API方式: REST, GraphQL, gRPCKent Ohashi
 
Team Geek Revisited
Team Geek RevisitedTeam Geek Revisited
Team Geek RevisitedKent Ohashi
 
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt Technologies
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt TechnologiesScala vs Clojure?: The Rise and Fall of Functional Languages in Opt Technologies
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt TechnologiesKent Ohashi
 
Clojureコレクションで探るimmutableでpersistentな世界
Clojureコレクションで探るimmutableでpersistentな世界Clojureコレクションで探るimmutableでpersistentな世界
Clojureコレクションで探るimmutableでpersistentな世界Kent Ohashi
 
英語学習者のためのフランス語文法入門: フランス語完全理解(?)
英語学習者のためのフランス語文法入門: フランス語完全理解(?)英語学習者のためのフランス語文法入門: フランス語完全理解(?)
英語学習者のためのフランス語文法入門: フランス語完全理解(?)Kent Ohashi
 
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミングJavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミングKent Ohashi
 
実用のための語源学入門
実用のための語源学入門実用のための語源学入門
実用のための語源学入門Kent Ohashi
 
メタプログラミング入門
メタプログラミング入門メタプログラミング入門
メタプログラミング入門Kent Ohashi
 
労働法の世界
労働法の世界労働法の世界
労働法の世界Kent Ohashi
 
Clojureで作る"simple"なDSL
Clojureで作る"simple"なDSLClojureで作る"simple"なDSL
Clojureで作る"simple"なDSLKent Ohashi
 
RDBでのツリー表現入門
RDBでのツリー表現入門RDBでのツリー表現入門
RDBでのツリー表現入門Kent Ohashi
 
Everyday Life with clojure.spec
Everyday Life with clojure.specEveryday Life with clojure.spec
Everyday Life with clojure.specKent Ohashi
 
たのしい多言語学習
たのしい多言語学習たのしい多言語学習
たのしい多言語学習Kent Ohashi
 
Ductモジュール入門
Ductモジュール入門Ductモジュール入門
Ductモジュール入門Kent Ohashi
 
Clojure REPL: The Good Parts
Clojure REPL: The Good PartsClojure REPL: The Good Parts
Clojure REPL: The Good PartsKent Ohashi
 
"Simple Made Easy" Made Easy
"Simple Made Easy" Made Easy"Simple Made Easy" Made Easy
"Simple Made Easy" Made EasyKent Ohashi
 
Clojurian Conquest
Clojurian ConquestClojurian Conquest
Clojurian ConquestKent Ohashi
 
GraphQL API in Clojure
GraphQL API in ClojureGraphQL API in Clojure
GraphQL API in ClojureKent Ohashi
 

Mais de Kent Ohashi (20)

インターフェース定義言語から学ぶモダンなWeb API方式: REST, GraphQL, gRPC
インターフェース定義言語から学ぶモダンなWeb API方式: REST, GraphQL, gRPCインターフェース定義言語から学ぶモダンなWeb API方式: REST, GraphQL, gRPC
インターフェース定義言語から学ぶモダンなWeb API方式: REST, GraphQL, gRPC
 
Team Geek Revisited
Team Geek RevisitedTeam Geek Revisited
Team Geek Revisited
 
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt Technologies
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt TechnologiesScala vs Clojure?: The Rise and Fall of Functional Languages in Opt Technologies
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt Technologies
 
Clojureコレクションで探るimmutableでpersistentな世界
Clojureコレクションで探るimmutableでpersistentな世界Clojureコレクションで探るimmutableでpersistentな世界
Clojureコレクションで探るimmutableでpersistentな世界
 
英語学習者のためのフランス語文法入門: フランス語完全理解(?)
英語学習者のためのフランス語文法入門: フランス語完全理解(?)英語学習者のためのフランス語文法入門: フランス語完全理解(?)
英語学習者のためのフランス語文法入門: フランス語完全理解(?)
 
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミングJavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
 
実用のための語源学入門
実用のための語源学入門実用のための語源学入門
実用のための語源学入門
 
メタプログラミング入門
メタプログラミング入門メタプログラミング入門
メタプログラミング入門
 
労働法の世界
労働法の世界労働法の世界
労働法の世界
 
Clojureで作る"simple"なDSL
Clojureで作る"simple"なDSLClojureで作る"simple"なDSL
Clojureで作る"simple"なDSL
 
RDBでのツリー表現入門
RDBでのツリー表現入門RDBでのツリー表現入門
RDBでのツリー表現入門
 
GraphQL入門
GraphQL入門GraphQL入門
GraphQL入門
 
Everyday Life with clojure.spec
Everyday Life with clojure.specEveryday Life with clojure.spec
Everyday Life with clojure.spec
 
たのしい多言語学習
たのしい多言語学習たのしい多言語学習
たのしい多言語学習
 
Ductモジュール入門
Ductモジュール入門Ductモジュール入門
Ductモジュール入門
 
Clojure REPL: The Good Parts
Clojure REPL: The Good PartsClojure REPL: The Good Parts
Clojure REPL: The Good Parts
 
"Simple Made Easy" Made Easy
"Simple Made Easy" Made Easy"Simple Made Easy" Made Easy
"Simple Made Easy" Made Easy
 
Clojurian Conquest
Clojurian ConquestClojurian Conquest
Clojurian Conquest
 
GraphQL API in Clojure
GraphQL API in ClojureGraphQL API in Clojure
GraphQL API in Clojure
 
法学入門
法学入門法学入門
法学入門
 

Último

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburgmasabamasaba
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durbanmasabamasaba
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsBert Jan Schrijver
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 

Último (20)

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

From Java To Clojure (English version)

  • 1. From Java To Clojure - Adieu Java -
  • 2. Self-introduction /laʒenɔʁɛ̃k/lagénorhynque (defprofile lagénorhynque :name "Kent OHASHI" :account @lagenorhynque :company "Opt, Inc." :languages [Clojure Haskell Python Scala English français Deutsch русский] :interests [programming language-learning mathematics])
  • 4. Java as a language
  • 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
  • 12. Clojure as a FP language
  • 13. Immutable List, Vector, Map, Set, etc. user=> '(1 2 3) (1 2 3) user=> [1 2 3] [1 2 3] user=> {:a 1 :b 2 :c 3} {:a 1, :b 2, :c 3} user=> #{1 2 3} #{1 3 2}
  • 14. Higher-order functions (filter, map, reduce, etc.) user=> (def xs [1 2 3]) #'user/xs user=> (filter odd? xs) (1 3) user=> (map #(* % %) xs) (1 4 9) user=> (reduce + 0 xs) 6 user=> (reduce + 0 (map #(* % %) (filter odd? xs))) 10 user=> (->> xs #_=> (filter odd?) #_=> (map #(* % %)) #_=> (reduce + 0)) 10
  • 15. BTW, #( ) is #(* % %) ↓↓↓ (fn [x] (* x x)) a reader macro equivalent as above.
  • 16. BTW, ->> is (->> a (f x) (g y) (h z)) ↓↓↓ (h z (g y (f x a))) a macro (a kind of threading macros) expanded as above.
  • 17. Lazy sequences user=> (def nats (iterate inc 0)) #'user/nats user=> (take 10 nats) (0 1 2 3 4 5 6 7 8 9) user=> (take-while #(< % 10) nats) (0 1 2 3 4 5 6 7 8 9)
  • 18. Clojure as a Lisp dialect
  • 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)))
  • 22. first(≒ car), rest(≒ cdr), cons, ... user=> (def xs [1 2 3]) #'user/xs user=> (first xs) 1 user=> (rest xs) (2 3) user=> (cons 0 xs) (0 1 2 3)
  • 23. S-expression code can be treated as data (code as data; )homoiconicity user=> (first '(def xs [1 2 3])) def user=> (rest '(def xs [1 2 3])) (xs [1 2 3]) user=> (cons 'def '(xs [1 2 3])) (def xs [1 2 3]) user=> (eval (cons 'def '(xs [1 2 3]))) #'user/xs
  • 24. Lisp macros powerful compile-time metaprogramming facility user=> (defmacro unless ; just a reimplementation of clojure.core/if-not macro #_=> ([test then] #_=> `(unless ~test ~then nil)) #_=> ([test then else] #_=> `(if (not ~test) #_=> ~then #_=> ~else))) #'user/unless user=> (unless (= 1 2) :ok) :ok user=> (macroexpand '(unless (= 1 2) :ok)) (if (clojure.core/not (= 1 2)) :ok nil)
  • 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
  • 27. Clojure as a JVM language
  • 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")
  • 30. destructive initialisation/setting // Java java.util.Map<String, Integer> m = new java.util.HashMap<>(); m.put("a", 1); m.put("b", 2); m.put("c", 3); return m; ;; Clojure (doto (java.util.HashMap.) (.put "a" 1) (.put "b" 2) (.put "c" 3))
  • 31. method chaining // Java new StringBuilder() .append("a") .append("b") .append("c") .toString() ;; Clojure (.. (StringBuilder.) (append "a") (append "b") (append "c") toString) ;; or (-> (StringBuilder.) (.append "a") (.append "b") (.append "c") .toString)
  • 32. Interoperating with Java collection API Java collection → Clojure function user=> (def xs (doto (java.util.ArrayList.) #_=> (.add 1) #_=> (.add 2) #_=> (.add 3))) #'user/xs user=> (class xs) java.util.ArrayList user=> xs [1 2 3] user=> (map inc xs) (2 3 4)
  • 33. Clojure collection → Java method user=> (def xs [1 2 3 4 5]) #'user/xs user=> (class xs) clojure.lang.PersistentVector user=> (instance? java.util.List xs) true user=> (.subList xs 1 4) [2 3 4]
  • 34. cf. usage example of Google Sheets API (Java) // Java public Integer duplicateWorksheet(Sheets sheets, String spreadsheetId, Integer worksheetId, Strin List<Request> reqs = Arrays.asList( new Request().setDuplicateSheet( new DuplicateSheetRequest().setSourceSheetId(worksheetId) .setNewSheetName(worksheetName) .setInsertSheetIndex(1) ) ); return executeUpdate(sheets, spreadsheetId, worksheetId, reqs) .getReplies() .get(0) .getDuplicateSheet() .getProperties() .getSheetId(); } ;; Clojure (defn duplicate-worksheet [sheets spreadsheet-id worksheet-id worksheet-name] (let [reqs [(-> (Request.) (.setDuplicateSheet (-> (DuplicateSheetRequest.) (.setSourceSheetId worksheet-id) (.setNewSheetName worksheet-name) (.setInsertSheetIndex (int 1)))))]] (-> (execute-update sheets spreadsheet-id worksheet-id reqs) .getReplies first .getDuplicateSheet .getProperties .getSheetId)))
  • 36. If you use Clojure, with the power of FP, Lisp and Java you can program more simply, more freely!!
  • 37. Vive les S-expressions ! Long live S-expressions!
  • 38. Further Reading : Clojure o cial site : Clojure build tool : Clojure build tool : Clojure online REPL : ClojureScript online REPL Chapter 7: Clojure Clojure Leiningen Boot Try Clojure Replumb REPL Seven Languages in Seven Weeks Programming Clojure (2nd edition)