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
260
軽量デバッグツールPostmortemの紹介.pdf
athos
1
180
Clojure 1.10 概要紹介
athos
3
610
やってみる!clojure.spec
athos
4
950
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.6k
(= ? (+ nREPL Docker))
athos
0
480
clojure.specの話
athos
3
2.2k
Other Decks in Programming
See All in Programming
C#/.NETのこれまでのふりかえり
tomokusaba
1
140
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
3
350
ピクシブ百科事典のWebフロントエンドパフォーマンス改善
higara
0
230
デプロイを任されたので、教わった通りにデプロイしたら障害になった件 ~俺のやらかしを越えてゆけ~
techouse
50
31k
役立つログに取り組もう
irof
24
7.7k
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
120
CSC305 Lecture 13
javiergs
PRO
0
120
Amazon Neptuneで始めてみるグラフDB-OpenSearchによるグラフの全文検索-
satoshi256kbyte
4
290
とにかくAWS GameDay!AWSは世界の共通言語!.pdf / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
0
160
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
120
Vue3の一歩踏み込んだパフォーマンスチューニング2024
hal_spidernight
3
2.9k
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1365
200k
A better future with KSS
kneath
238
17k
Writing Fast Ruby
sferik
626
60k
Docker and Python
trallard
40
3k
Art, The Web, and Tiny UX
lynnandtonic
296
20k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
360
Become a Pro
speakerdeck
PRO
24
4.9k
Being A Developer After 40
akosma
86
590k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
5
140
Statistics for Hackers
jakevdp
796
220k
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ͷجૅΛ࡞Δཁૉͷͭ ‣ ϚΫϩڧྗͳϝλϓϩάϥϛϯάͷπʔϧ ‣ ࣮։ൃͰ͑Δ͞·͟·ͳศརϚΫϩ͕͋Δ ‣ ͨͩ͠ཚ༻͗͢͠Δͱίʔυ͕ಡΊͳ͘ͳΔͷͰɺ ຊʹඞཁͳγνϡΤʔγϣϯΛݟۃΊΔ͜ͱ