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
280
軽量デバッグツールPostmortemの紹介.pdf
athos
1
190
Clojure 1.10 概要紹介
athos
3
610
やってみる!clojure.spec
athos
4
970
kitchen-async: a promising (?) Promise library, or a poor man's core.async
athos
3
410
Clojure 1.9 概要紹介
athos
4
1.4k
ここ最近のClojureScript
athos
5
1.7k
(= ? (+ nREPL Docker))
athos
0
490
clojure.specの話
athos
3
2.2k
Other Decks in Programming
See All in Programming
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
360
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
340
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
160
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
Exploring: Partial and Independent Composables
blackbracken
0
100
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
840
선언형 UI에서의 상태관리
l2hyunwoo
0
180
MCP with Cloudflare Workers
yusukebe
2
220
Spatial Rendering for Apple Vision Pro
warrenm
0
110
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1030
460k
Building an army of robots
kneath
302
44k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Designing for Performance
lara
604
68k
Being A Developer After 40
akosma
87
590k
Into the Great Unknown - MozCon
thekraken
33
1.5k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Automating Front-end Workflow
addyosmani
1366
200k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
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ͷجૅΛ࡞Δཁૉͷͭ ‣ ϚΫϩڧྗͳϝλϓϩάϥϛϯάͷπʔϧ ‣ ࣮։ൃͰ͑Δ͞·͟·ͳศརϚΫϩ͕͋Δ ‣ ͨͩ͠ཚ༻͗͢͠Δͱίʔυ͕ಡΊͳ͘ͳΔͷͰɺ ຊʹඞཁͳγνϡΤʔγϣϯΛݟۃΊΔ͜ͱ