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
C++でシェーダを書く
fadis
6
4.1k
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.5k
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
900
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
940
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
700
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Click-free releases & the making of a CLI app
oheyadam
2
120
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
距離関数を極める! / SESSIONS 2024
gam0022
0
290
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
73
9.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Code Review Best Practice
trishagee
64
17k
Site-Speed That Sticks
csswizardry
0
28
Agile that works and the tools we love
rasmusluckow
327
21k
Why Our Code Smells
bkeepers
PRO
334
57k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
A better future with KSS
kneath
238
17k
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ͷجૅΛ࡞Δཁૉͷͭ ‣ ϚΫϩڧྗͳϝλϓϩάϥϛϯάͷπʔϧ ‣ ࣮։ൃͰ͑Δ͞·͟·ͳศརϚΫϩ͕͋Δ ‣ ͨͩ͠ཚ༻͗͢͠Δͱίʔυ͕ಡΊͳ͘ͳΔͷͰɺ ຊʹඞཁͳγνϡΤʔγϣϯΛݟۃΊΔ͜ͱ