Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Functional Programming with Clojure
Search
James Hughes
September 23, 2014
Programming
1
100
Functional Programming with Clojure
WWCB Clojure session
James Hughes
September 23, 2014
Tweet
Share
More Decks by James Hughes
See All by James Hughes
Tyrannosaurus Rx
kouphax
0
110
React
kouphax
2
690
Play for (Java|Scala)
kouphax
0
100
Devops: A Case Study
kouphax
0
65
Scala for C# Developers
kouphax
5
2.5k
Dropwizard - Production Ready Web Services
kouphax
3
1.5k
Scala for Fun & Profit
kouphax
3
610
What Agile Means To Me
kouphax
0
120
Neo4J: A Case Study
kouphax
3
600
Other Decks in Programming
See All in Programming
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
910
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
510
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
1.6k
僕がつくった48個のWebサービス達
yusukebe
18
17k
Vaporモードを大規模サービスに最速導入して学びを共有する
kazukishimamoto
4
4.3k
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.3k
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
270
のびしろを広げる巻き込まれ力:偶然を活かすキャリアの作り方/oso2024
takahashiikki
1
410
生成 AI を活用した toitta 切片分類機能の裏側 / Inside toitta's AI-Based Factoid Clustering
pokutuna
0
570
レガシーな Android アプリのリアーキテクチャ戦略
oidy
1
170
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
Amazon Neptuneで始めてみるグラフDB-OpenSearchによるグラフの全文検索-
satoshi256kbyte
4
320
Featured
See All Featured
4 Signs Your Business is Dying
shpigford
180
21k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Agile that works and the tools we love
rasmusluckow
327
21k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Optimizing for Happiness
mojombo
376
69k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
7
150
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
The Invisible Side of Design
smashingmag
297
50k
Writing Fast Ruby
sferik
626
61k
The World Runs on Bad Software
bkeepers
PRO
65
11k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
107
49k
Transcript
======================================== ! FUNCTIONAL PROGRAMMING WITH CLOJURE ! ========================================
1. SIDE EFFECT FREE 2. IMMUTABILITY 3. FIRST CLASS FUNCTIONS
4. FUNCTION BASED CONTROL FLOW ======================================== FUNCTIONAL PROGRAMMING ======================================== [1] ========================================
[2] +-----------------------+ | IMPERATIVE SHELL | | | | +-------------------+
| | | FUNCTIONAL CORE | | | | | | | +-------------------+ | +-----------------------+
1. LISP DIALECT 2. JVM & JS TARGETS 3. DYNAMIC
4. HOMOICONICITY 5. IMMUTABILITY 6. PLATFORM INTEROP 7. SMALL POWERFUL CORE 8. CONCURRENCY ======================================== CLOJURE ======================================== ========================================
======================================== ! SYNTAXING? ! ========================================
======================================== ! ======================================== 1 + 2
======================================== ! ======================================== (+ 1 2)
======================================== ! ======================================== add(1, 2)
======================================== ! ======================================== (add 1, 2)
======================================== ! ======================================== (add 1 2)
======================================== ! ======================================== 1 / 2 * 3
======================================== ! ======================================== (/ 1 (* 2 3))
======================================== ! CLOJURE BY EXAMPLE ! ========================================
➜ brew install leiningen ---------------------------------------- ➜ curl -Lo lein http://bit.ly/1m8fHx2
➜ chmod a+x lein ➜ ./lein ======================================== INSTALLING LEININGEN ======================================== ========================================
➜ lein repl ! nREPL server started on port ...
Clojure 1.6.0 ! user=> ======================================== THE REPL ======================================== ========================================
user=> (doc map) ; ------------------ ! user=> (find-doc "fold") ;
------------------ ======================================== THE REPL ======================================== ========================================
======================================== ! DATA TYPES ! ========================================
(class 1) (class "Hello") (class 1.0) (class \H) (class true)
java.lang.Long java.lang.String java.lang.Double java.lang.Character java.lang.Boolean ======================================== DATA TYPES ======================================== ========================================
(class nil) (class (fn [] 1)) (class 5/3) (class :test)
(class 'a) nil clojure.lang.IFn clojure.lang.Ratio clojure.lang.Keyword clojure.lang.Symbol ======================================== DATA TYPES ======================================== ========================================
(class '(1 2)) (class [1 2]) (class #{1 2}) (class
{:a 1 :b 2}) clojure.lang.List* clojure.lang.Vector* clojure.lang.Set* clojure.lang.Map* ======================================== DATA TYPES ======================================== ========================================
(= __ true) (= __ (= 2 2/1)) (= :a
(keyword __)) (= __ (== 2.0 2)) (= __ (= "a" :a 'a)) (= __ (= 2 2/1)) (not= __ false) (= false (not __)) ======================================== POP QUIZ HOT SHOT ======================================== ======================================== [3]
======================================== ! LISTS, VECTORS & SETS ! ========================================
(list 1 2 3 2 1) (vector 1 2 3
2 1) (hash-set 1 2 3 2 1) '(1 2 3 2 1) [1 2 3 2 1] #{1 2 3} ======================================== LISTS, VECTORS & SETS ======================================== ========================================
(= __ (count '(42))) (= __ (conj [1 2] 3))
(= __ (cons 1 [2 3])) (= __ (first [1 2 3])) (= __ (last [1 2 3])) ======================================== LISTS, VECTORS & SETS ======================================== ========================================
(= __ (rest [1 2 3])) (= __ (nth [1
2 3] 2)) (= __ (peek [1 2 3])) (= __ (pop [1 2 3])) (= __ (rest [])) ======================================== LISTS, VECTORS & SETS ======================================== ========================================
======================================== ! MAPS ! ========================================
(hash-map {:a 1}) (hash-map {:a 1 :b}) { :a 1
} ERROR! ======================================== MAPS ======================================== ========================================
(= __ (get {:b 2} :b)) (= __ ({:a 1}
:a)) (= __ (:a {:a 1})) (= __ (:b {:a 1})) (= __ (:b {:a 1} 2)) ======================================== MAPS ======================================== ========================================
(= __ (count {:a 1})) (= __ (:b {:a 1}
2)) (= __ (assoc {:a 1} :b 2)) (= __ (dissoc {:a 1 :b 2} :a)) (= __ (dissoc {:a 1 :b 2} :a :b)) ======================================== MAPS ======================================== ========================================
(= __ (contains? {:a nil :b nil} :b)) (= __
(keys {:a 1 :b 2})) (= __ (vals {:a 1 :b 2})) ======================================== MAPS ======================================== ========================================
======================================== ! FUNCTIONS ! ========================================
(def sq (fn [a] (* a a))) (defn sq [a]
(* a a)) (def sq #(* % %)) ======================================== FUNCTIONS ======================================== ========================================
(= __ ((fn [n] (* 5 n)) 2)) (= __
(#(* 15 %) 4)) (= __ (#(+ %1 %2 %3) 4 5 6)) (= __ (#(* 15 %2) 1 2)) (= 9 (((fn [] ___)) 4 5)) ======================================== FUNCTIONS ======================================== ========================================
======================================== ! CONDITIONALS ! ========================================
(= __ (if (false? (= 4 5)) :a :b)) (=
__ (if (> 4 3) [])) ======================================== CONDITIONALS ======================================== ========================================
(let [x 5] (= :your-road (cond (= x __) :road-not-taken
(= x __) :another-not-taken :else __))) ======================================== CONDITIONALS ======================================== ========================================
(let [choice 5] (= :your-road (case choice __ :road-not-taken __
:your-road :another-not-taken))) ======================================== CONDITIONALS ======================================== ========================================
======================================== ! LOOPING ! ========================================
(= __ (loop [v 1] (if-not (> v 5) (recur
(inc v)) v)) ======================================== LOOPING ======================================== ========================================
======================================== ! HIGHER ORDER FUNCTIONS ! ========================================
(= [__ __ __] (map #(* 4 %) [1 2
3])) (= __ (filter nil? [:a :b nil :c :d])) (= __ (reduce * [1 2 3 4])) ======================================== HIGHER ORDER FUNCTIONS ======================================== ========================================
======================================== ! LAZY SEQUENCES ! ========================================
(= __ (range 1 5)) (= __ (range 5)) (=
[0 1 2 3 4 5] (take __ (range 100))) (= __ (take 20 (iterate inc 0))) (= [:a :a :a :a :a :a] (repeat __ __)) ======================================== LAZY SEQUENCES ======================================== ========================================
======================================== ! USEFUL MACROS ! ========================================
(= __ (-> "a b c d" .toUpperCase (.replace "A"
"X") (.split " ") first)) ======================================== USEFUL MACROS ======================================== ========================================
(= __ (->> (range) (filter even?) (take 10) (reduce +)))
======================================== USEFUL MACROS ======================================== ========================================
(= __ (try (/ 1 0) true (catch Exception e
false))) ======================================== USEFUL MACROS ======================================== ========================================
======================================== ! ATOMS ! ========================================
(let [my-atom (atom 1)] (= __ @my-atom) (swap! my-atom inc)
(= __ @my-atom) (reset! my-atom 4) (= __ @my-atom)) ======================================== ATOMS ======================================== ========================================
1. JAVA INTEROP 2. MACROS 3. DESTRUCTURING 4. RECORDS 5.
PROTOCOLS 6. COMPREHENSION 7. TRANSDUCERS 8. CLOJURESCRIPT ======================================== (REST CLOJURE) ======================================== ========================================
======================================== IT’S DANGEROUS TO GO ALONE… ======================================== ======================================== 1. CLOJURE
GRIMOIRE 2. WEIRD & WONDERFUL CHARACTERS OF CLOJURE 3. CLOJURE DOCS 4. CLOJURE FOR THE BRAVE AND TRUE
======================================== DEAD TREE EDITION ======================================== ======================================== 1. JOY OF CLOJURE
2ND EDITION 2. PROGRAMMING CLOJURE 3. FUNCTIONAL THINKING 4. STRUCTURE & INTERPRETATION OF COMPUTER PROGRAMS
======================================== ATTRIBUTION ======================================== [1]: http://bit.ly/learning-clojure [2]: http://bit.ly/destroy-all-software [3]: http://bit.ly/clojure-koans [4]:
http://bit.ly/clojure-gist ========================================