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
Clojureの基礎 〜マクロ編〜
Search
OHTA Shogo
June 11, 2016
Programming
2
600
Clojureの基礎 〜マクロ編〜
2016/6/11 プログラミング言語基礎勉強会のLT発表資料です。
OHTA Shogo
June 11, 2016
Tweet
Share
More Decks by OHTA Shogo
See All by OHTA Shogo
テンクーでのClojure活用事例
athos
0
270
軽量デバッグツールPostmortemの紹介.pdf
athos
1
190
Clojure 1.10 概要紹介
athos
3
610
やってみる!clojure.spec
athos
4
960
kitchen-async: a promising (?) Promise library, or a poor man's core.async
athos
3
400
Clojure 1.9 概要紹介
athos
4
1.4k
ここ最近のClojureScript
athos
5
1.7k
(= ? (+ nREPL Docker))
athos
0
480
clojure.specの話
athos
3
2.2k
Other Decks in Programming
See All in Programming
Outline View in SwiftUI
1024jp
1
330
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
cmp.Or に感動した
otakakot
3
200
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.2k
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
CSC509 Lecture 12
javiergs
PRO
0
160
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
140
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
940
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
Featured
See All Featured
Practical Orchestrator
shlominoach
186
10k
The World Runs on Bad Software
bkeepers
PRO
65
11k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Become a Pro
speakerdeck
PRO
25
5k
4 Signs Your Business is Dying
shpigford
180
21k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Happy Clients
brianwarren
98
6.7k
Speed Design
sergeychernyshev
25
620
Building Adaptive Systems
keathley
38
2.3k
GitHub's CSS Performance
jonrohan
1030
460k
Transcript
$MPKVSFͷجૅ ϓϩάϥϛϯάݴޠجૅษڧձ 2016/06/11 @athos0220
ࣗݾհ ‣ 5XJUUFS!BUIPT ‣ χϟϯύε ג ॴଐ ‣ $MPKVSFίϯτϦϏϡʔλ
$MPKVSFͷجૅΛ࡞Δͷ ࠓճ-JTQͱͯ͠ͷಛʹϑΥʔΧε -JTQ ؔ ϓϩάϥϛϯά ରత ϓϩάϥϛϯά +7.
-JTQ
-JTQ ‣ લஔه๏͕ಛ ‣ ࠷ॳͷཁૉ͕ΦϖϨʔλɺͦΕҎ͕߱Ҿ ‣ ݴޠͷίΞ͕ඇৗʹγϯϓϧ (defn distance [x
y] (sqrt (+ (* x x) (* y y))))
-JTQ ‣ લஔه๏͕ಛ ‣ ࠷ॳͷཁૉ͕ΦϖϨʔλɺͦΕҎ͕߱Ҿ ‣ ݴޠͷίΞ͕ඇৗʹγϯϓϧ (defn distance [x
y] (sqrt (+ (* x x) (* y y)))) ΦϖϨʔλ Ҿ
$PEFBT%BUB ‣ $MPKVSFίʔυΛ؆୯ʹσʔλͱͯ͠ѻ͑Δ ‣ $MPKVSFͷσʔλͰίʔυΛॻ͍͍ͯΔͱ͍͑Δ (read-string “(* x x)”) ;=>
(* x x)
$PEFBT%BUB ‣ $MPKVSFίʔυΛ؆୯ʹσʔλͱͯ͠ѻ͑Δ ‣ $MPKVSFͷσʔλͰίʔυΛॻ͍͍ͯΔͱ͍͑Δ (read-string “(* x x)”) ;=>
(* x x) ͭͷγϯϘϧ Y Y͔ΒͳΔϦετ
ॲཧܥͰͷྲྀΕ ίʔυ จࣈྻ ίʔυ σʔλ όΠτίʔυ
ॲཧܥͰͷྲྀΕ ίʔυ จࣈྻ ίʔυ σʔλ όΠτίʔυ Ϧʔυ ίϯύΠϧ
ϚΫϩ
ϚΫϩͱ ‣ ίʔυ͔ΒίʔυͷมΛఆٛ͢Δؔ ‣ Ϣʔβ͕͖ͳΑ͏ʹߏจΛఆٛͰ͖ΔΈ ‣ ૉͳ͕Βڧྗͳϝλϓϩάϥϛϯάͷπʔϧ
ॲཧܥͰͷྲྀΕ ίʔυ จࣈྻ ίʔυ σʔλ όΠτίʔυ Ϧʔυ ίϯύΠϧ
ॲཧܥͰͷྲྀΕ ίʔυ จࣈྻ ίʔυ σʔλ όΠτίʔυ Ϧʔυ ίϯύΠϧ ϚΫϩల։
PSΛఆٛͯ͠ΈΔ ‣ ͭΊͷࣜͷ͕USVFͩͬͨΒͭΊΛབྷධՁ (or (expr-1) (expr-2)) (let [v (expr-1)] (if
v v (expr-2))) ల։
PSΛఆٛͯ͠ΈΔ (defmacro or [expr1 expr2] `(let [v# ~expr1] (if v#
v# ~expr2)))
XJUIPQFOΛఆٛͯ͠ΈΔ ‣ +BWBͷUSZXJUISFTPVSDFTͷΑ͏ͳߏจ (with-open [f (reader “foo”)] (write-to-file f)) (let
[f (reader “foo”)] (try (write-to-file f) (finally (.close f)))) ల։
XJUIPQFOΛఆٛͯ͠ΈΔ (defmacro with-open [[name file] body] `(let [~name ~file] (try
~body (finally (.close ~name)))))
࣮։ൃͰͷϚΫϩ
$PNQPKVSF ‣ $MPKVSFͷϧʔςΟϯάϥΠϒϥϦ (defroutes app-routes (GET “/” [] (index)) (GET
“/en” [] (index)) (GET “/fr” [] (index-fr)) (GET “/:greeting” [greeting] (view greeting)))
DPSFNBUDI ‣ ύλʔϯϚονϥΠϒϥϦ (match inst [:mov z x] (recur (subst
z x) insts) [:add z x y] (recur (do-op + z x y) insts) [:sub z x y] (recur (do-op - z x y) insts) [:push z x] (recur (push z x) insts) [:pop z] (recur (pop z) insts) [:jnz l] (if (:flag env) [l env] (recur env insts)) [:jz l] (if (:flag env) (recur env insts) [l env] …)
DPSFUZQFE ‣ ੩తܕνΣοΫϥΠϒϥϦ (ann new-file [(U URI String) -> File])
(defn new-file [s] (if (string? s) (File. ^String s) (File. ^URI s)))
DPSFBTZOD ‣ νϟωϧϕʔεͷඇಉظϓϩάϥϛϯάϥΠϒϥϦ (go (while true (let [v (<! ch)]
(println v)))) (go (loop [i 0] (>! ch i) (recur (inc i)))) ड৴ଆίʔυ ૹ৴ଆίʔυ
͓·͚ ‣ ϚΫϩඇৗʹڧྗͳͷͰѱ༻ͯ͠ݴޠࣗମΛେ෯ ʹม͑ͯ͠·͏͜ͱͰ͖Δ ‣ ྫʣΰϧϑ༻3VCZॲཧܥHPSVCZͷ฿ ϝιουΛॖܗͰݺΔ qFYNBUDIJOH
- 1.up(10) {|i| p i} - [1,4,9].ew{|x,i| ps “#{i}:#{x}”} upto each_with_index puts
HPDMPKVSF (doseq [[l n] (frequencies (map #(count (str %)) (keys
(ns-publics ’clojure.core))))] (printf “%2d %s\n” l (apply str (repeat n \*)))) ΦϦδφϧͷίʔυ
HPDMPKVSF (doseq [[l n] (frequencies (map #(count (str %)) (keys
(ns-publics ’clojure.core))))] (printf “%2d %s\n” l (apply str (repeat n \*)))) (goclojure (dq [[l n] (qs (mp #(ou (sr %)) (ks (nsb ’clojure.core))))] (pf “%2d %s\n” l (ay sr (rep n \*)))) ΦϦδφϧͷίʔυ HPDMPKVSFΛͬͯॻ͖͑ͨίʔυ
·ͱΊ ‣ -JTQͰ͋Δ͜ͱ$MPKVSFͷجૅΛ࡞Δཁૉͷͭ ‣ ϚΫϩڧྗͳϝλϓϩάϥϛϯάͷπʔϧ ‣ ࣮։ൃͰ͑Δ͞·͟·ͳศརϚΫϩ͕͋Δ ‣ ͨͩ͠ཚ༻͗͢͠Δͱίʔυ͕ಡΊͳ͘ͳΔͷͰɺ ຊʹඞཁͳγνϡΤʔγϣϯΛݟۃΊΔ͜ͱ