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
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
php-conference-japan-2024
tasuku43
0
320
Go の GC の不得意な部分を克服したい
taiyow
3
790
MCP with Cloudflare Workers
yusukebe
2
220
Recoilを剥がしている話
kirik
5
6.8k
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
290
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
ドメインイベント増えすぎ問題
h0r15h0
2
350
From Translations to Multi Dimension Entities
alexanderschranz
2
130
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Visualization
eitanlees
146
15k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
GitHub's CSS Performance
jonrohan
1030
460k
Speed Design
sergeychernyshev
25
670
Into the Great Unknown - MozCon
thekraken
33
1.5k
For a Future-Friendly Web
brad_frost
175
9.4k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
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ͷجૅΛ࡞Δཁૉͷͭ ‣ ϚΫϩڧྗͳϝλϓϩάϥϛϯάͷπʔϧ ‣ ࣮։ൃͰ͑Δ͞·͟·ͳศརϚΫϩ͕͋Δ ‣ ͨͩ͠ཚ༻͗͢͠Δͱίʔυ͕ಡΊͳ͘ͳΔͷͰɺ ຊʹඞཁͳγνϡΤʔγϣϯΛݟۃΊΔ͜ͱ