$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Clojure 1.10 概要紹介
Search
OHTA Shogo
November 29, 2018
Programming
3
610
Clojure 1.10 概要紹介
2018/11/29のLisp meetup #70の発表資料です。
OHTA Shogo
November 29, 2018
Tweet
Share
More Decks by OHTA Shogo
See All by OHTA Shogo
テンクーでのClojure活用事例
athos
0
280
軽量デバッグツールPostmortemの紹介.pdf
athos
1
190
やってみる!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
clojure.specの話(仮)
athos
2
330
Other Decks in Programming
See All in Programming
プロダクトの品質に コミットする / Commit to Product Quality
pekepek
1
620
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
2
280
MoQとか勉強会#2 発表資料
yuki_uchida
2
450
cmp.Or に感動した
otakakot
3
340
Cognitoが大型アップデート!Managed Loginとパスワードレスログインを実際に使ってみた@しむそくRadio Special Day1
tmhirai
3
240
イマのCSSでできる インタラクション最前線 + CSS最新情報
clockmaker
5
3.8k
layerx_20241129.pdf
kyoheig3
2
250
macOS なしで iOS アプリを開発する(※ただし xxx に限る)
mitsuharu
1
170
Full stack testing :: basic to basic
up1
1
870
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
150
Criando Commits Incríveis no Git
marcelgsantos
1
130
デザインパターンで理解するLLMエージェントの作り方 / How to develop an LLM agent using agentic design patterns
rkaga
11
3.2k
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
Facilitating Awesome Meetings
lara
50
6.1k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Faster Mobile Websites
deanohume
305
30k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Making Projects Easy
brettharned
116
5.9k
Documentation Writing (for coders)
carmenintech
65
4.5k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Transcript
$MPKVSF֓ཁհ -JTQNFFUVQPO !BUIPT
֓ཁ ‣ ઌ ɺ3$͕ϦϦʔε BMQIBϦϦʔε CFUBϦϦʔε
3$ϦϦʔε ‣ pOBMϦϦʔεલͳͷͰɺͰͷओཁͳมߋʹ ͍͓ͭͯ͞Β͍
$MPKVSFͷओཁͳมߋ ‣ Τϥʔϝοηʔδͷվળ ‣ EBUBGZ ‣ ϝλσʔλʹΑΔϓϩτίϧͷ֦ு ‣ QSFQM ‣
UBQ
Τϥʔϝοηʔδͷվળ ‣ ࠓճͷϦϦʔεʹ͓͚ΔҰ൪ͷۄ ‣ Τϥʔϝοηʔδͱͯ͠ɺϢʔβʹͲ͏͍ͬͨใΛఏࣔ ͢Δ͔Λൈຊతʹཧ ‣ ඪ४3&1-ͰͷΤϥʔϝοηʔδվળ͚ͩͰͳ͘ଞͷ։ൃ ڥͰΤϥʔใΛศརʹ׆༻Ͱ͖ΔΑ͏ͳ"1*Λఏڙ ‣
·ͩඪ४ͷΤϥʔϝοηʔδඞ͔ͣ͠Γ͍͢Θ͚ Ͱͳ͍ͷͰɺࠓޙͷ։ൃڥଆͷվળ͕ظ͞ΕΔ
Τϥʔͷ͔Γʹ͘͞ͷݪҼ ‣ $MPKVSFͷଟ͘ͷؔΨʔϕδΠϯɾΨʔϕδΞτ ҾνΣοΫ͕ͳ͍ͨΊɺClassCastException IllegalArgumentExceptionɺతʹΤϥʔՕॴΛࣔ ͞ͳ͍Τϥʔ͕ग़ͯ͠·͏ DMPKVSFTQFDʹΑͬͯղܾ͞Ε͍ͯ͘ݟࠐΈ ʙ
‣ Τϥʔͷใྔ͕ଟ͗ͯ͢Կ͕ॏཁͳͷ͔͔Γʹ͍͘ ಛʹTQFDͷΤϥʔใ͕େʹͳΓ͕ͪ ‣ ॲཧܥଆͷݺͼग़͕͠ελοΫτϨʔεʹฆΕࠐΜͰ͠·͏ ॲཧܥ͕Ͳ͜ͰΤϥʔΛݟ͚͔ͭͨॏཁͰͳ͍
Τϥʔͷཧ ‣ ͲͷϑΣʔζͰग़ͨΤϥʔ͔ΛྨɺϑΣʔζຖʹ༗༻ͳใΛ࣋ͨͤΔ ϑΣʔζɿϦʔυ࣌ɺϚΫϩߏจνΣοΫ࣌ɺϚΫϩల։࣌ɺίϯύΠϧ ࣌ɺ࣮ߦ࣌ɺ݁Ռग़ྗ࣌ ‣ CompilerException ࣮ߦ࣌ΑΓલͷϑΣʔζͷΤϥʔ ͔Βex-data
ͰҎԼͷใΛڞ௨ͯ͠औಘՄೳʹ :clojure.error/phase Τϥʔ͕ൃੜͨ͠ϑΣʔζ :clojure.error/source Τϥʔ͕ൃੜͨ͠ιʔεϑΝΠϧ :clojure.error/line Τϥʔ͕ൃੜͨ͠ιʔεϑΝΠϧͷߦ൪߸ :clojure.error/column Τϥʔ͕ൃੜͨ͠ιʔεϑΝΠϧͷܻ :clojure.error/symbol ΤϥʔͷݪҼʹͳͬͨγϯϘϧ :clojure.error/class ΤϥʔΫϥε໊ :clojure.error/cause Τϥʔϝοηʔδ :clojure.error/spec εϖοΫΤϥʔ ͋Ε
ॏཁͷ͍ใͷݮ εϖοΫΤϥʔ σʔλ ਓؒʹͱͬͯ༗ӹͰͳ͍ ใදࣔ͠ͳ͍Α͏ʹ ͷϚΫϩߏจΤϥʔ ͷϚΫϩߏจΤϥʔ
ΤϥʔՕॴͷࢦఠ ‣ ϦʔυΤϥʔ ‣ ίϯύΠϧΤϥʔ ʁ ຊʹΓ͍ͨͷॲཧܥ͕ͲͷॲཧதʹΤϥʔΛ ݟ͚͔ͭͨͰͳ͘ίʔυͷͲ͜ʹΤϥʔ͕͔͋ͬͨ ʁ
ex-triageex-str ‣ ࣮ߦ࣌ΤϥʔҰൠʹ+BWBͷྫ֎ɾΤϥʔͷՄೳੑ +BWBͷྫ֎ɾΤϥʔͷதʹɺ$MPKVSFʹ߹ͷ͍͍ଐੑΛ ࣋ͨͳ͍ͷ͋Δ ‣ ex-triage ͋ΒΏΔΤϥʔΛ౷ҰతͳϑΥʔϚοτͷϚοϓσʔλʹ
ม͢Δ ϦϞʔτͰͭͳ͕ΔڥͰΤϥʔใΛΓͱΓ͢ΔϑΥʔ Ϛοτͱͯ͑͠Δ ‣ ex-str ex-triageΛจࣈྻԽ͢Δඪ४తͳํ๏
EBUBGZ ‣ DMPKVSFEBUBGZ ‣ ৽͍͠ϓϩτίϧDatafiableͱNavigable͕Ճ ‣ ͲͪΒͷϓϩτίϧৄࡉͳઆ໌·ͩͳ͍ ‣ جຊతʹΦϒδΣΫτΛʮσʔλԽʯ͢ΔͨΊͷͷ
EBUBGZ ‣ :extend-via-metadataʹ͍ͭͯޙड़ (defprotocol Datafiable :extend-via-metadata true (datafy [o] “return
a representation of o as data”)) (defprotocol Navigable :extend-via-metadata true (nav [coll k v] "return v in the context of coll and k (a key/index or nil)"))
EBUBGZͷ͍ํ ‣ ݱ࣌ͰɺΫϥεྫ֎গͷ࣮͕ఏڙ͞Ε͍ͯΔͷΈ (require ‘[clojure.datafy :as datafy]) (datafy/datafy java.io.Closeable) ;=>
{:bases #{java.lang.AutoCloseable}, :flags #{:interface :public :abstract}, :members {close [#clojure.reflect.Method{…}, :name java.io.Closeable} (datafy/datafy (ex-info “error” {})) ;=> {:cause “error!!”, :data {:value 42}, :trace [[user$eval199 invokeStatic "NO_SOURCE_FILE" 1] [user$eval199 invoke "NO_SOURCE_FILE" 1] [clojure.lang.Compiler eval "Compiler.java" 7176] …] :via [{:type clojure.lang.ExceptionInfo, :message “error!!", :data {:value 42}, :at [user$eval199 invokeStatic "NO_SOURCE_FILE" 1]}]}
EBUBGZͷิ ‣ ʮσʔλԽʯͱ͍͏ͱ༻్͕෯͘ײ͡Δ͕ɺ Throwable->mapͷΑ͏ʹɺΦϒδΣΫτͷΠϯεϖΫ γϣϯ༻్͕ϝΠϯʹࢥ͑Δ ݸਓతײ SFJGZͰ࡞ͬͨΦϒδΣΫτ͕෦తʹอ࣋͢Δใͷެ։
ಛʹεϖοΫΦϒδΣΫτͷΠϯεϖΫγϣϯɺτϥόʔε ‣ ΦϒδΣΫτͷγϦΞϥΠζͷ༻్͋·Γఆ͞Εͯ ͍ͳ͍͜ͱ͕ެࣜʹ΄ͷΊ͔͞Ε͍ͯΔ
ϝλσʔλʹΑΔϓϩτίϧͷ֦ு ‣ EBUBGZಋೖͷաఔͰऔΓೖΕΒΕͨ ‣ ͜Ε·ͰϓϩτίϧϨίʔυσʔλܕͰ࣮͢Δ ͔ɺextend-protocolextend-typeͰ֦ு͢Δ͔ͩͬͨ ‣ ͔ΒϝλσʔλʹΑΓϓϩτίϧΛ֦ுͰ͖ΔΑ͏ ʹͳΓɺΦϒδΣΫτຖͷଟ૬తͳৼΔ͍ΛఆٛՄೳʹ
ैདྷͷϓϩτίϧͷར༻๏ (defprotocol P (m [this])) ;; ϨίʔυʹΑΔ࣮ (defrecord R []
P (m [this] 42)) (m (->R)) ;=> 42 ;; extend-protocol/extend-typeʹΑΔ֦ு (extend-protocol P Long (m [this] this)) (m 101) ;=> 101
ϝλσʔλʹΑΔ֦ு ‣ :extend-via-metadata true Λࢦఆ͢Δͱɺϓϩτίϧ͕ ϝλσʔλʹΑΓ֦ுՄೳʹ (defprotocol P :extend-via-metadata true
(m [this])) (def obj (with-meta {:x 42} {`m (fn [this] (:x this))})) (m obj) ;=> 42 (m (with-meta obj {`m (fn [this] 43)})) ;=> 43
ϝλσʔλʹΑΔ֦ுͷҙ ‣ ϓϩτίϧͷఆٛ࣌ʹ:extend-via-metadataͷࢦఆ͕ ͳ͚ΕϝλσʔλʹΑΔ֦ு༗ޮʹͳΒͳ͍ ‣ ϓϩτίϧͷ࣮ͷ༏ઌॱҐ ϨίʔυɾσʔλܕʹΑΔ࣮ ϝλσʔλʹΑΔ֦ு
extend-protocolextend-typeʹΑΔ֦ு ‣ ϝλσʔλʹΑΔ֦ுΛ༗ޮʹͨ͠ϓϩτίϧͷϝιου ݺͼग़͠ੑೳ໘ͰͷΦʔόʔϔου͕͋Δ
QSFQM ‣ lQSPHSBNNBCMFz3&1- ‣ ৽͍͠ετϦʔϜϕʔε3&1- ‣ $MPKVSFϑΥʔϜΛೖྗʹͱΓɺߏԽ͞Εͨग़ྗΛฦ͢ ‣ Ͱಋೖ͞Εͨιέοταʔό͔Βར༻͠ɺϦϞʔτ 3&1-Λ࣮ݱ͢ΔͨΊʹ͏͜ͱΛఆ͞Ε͍ͯΔ
‣ 6OSFQMϓϩτίϧʹྨࣅ͢Δ෦͕ଟ͍ IUUQTHJUIVCDPN6OSFQMVOSFQM
QSFQMͷ͍ํ ‣ ιέοταʔόͷىಈ ‣ ΫϥΠΞϯτ͔Βͷଓ ‣ $ clojure -J-Dclojure.server.repl="{:port 5555
:accept clojure.core.server/io-prepl}" $ nc localhost 5555 (map inc [1 2 3]) {:tag :ret, :val "(2 3 4)", :ns "user", :ms 19, :form "(map inc [1 2 3])”} (dotimes [i 3] (Thread/sleep 1000) (println i)) {:tag :out, :val "0\n"} {:tag :out, :val "1\n"} {:tag :out, :val "2\n"} {:tag :ret, :val "nil", :ns "user", :ms 3214, :form "(dotimes [i 3] (Thread/sleep 1000) (println i))”}
ैདྷͷ3&1-ͷ ‣ ैདྷͷ3&1-Λιέοταʔό͔Β͏͜ͱΛߟ͑Δͱʮධ Ձ݁Ռ͔͠ฦͤͳ͍ʯ͜ͱͷ͕خ͘͠ͳ͍͜ͱ ‣ ͨͱ͑ʜ ධՁ͍ͯ͠Δ్தͰग़ྗ݁ՌɺධՁ݁ՌҎ֎ͷͷΛฦ͢ ͷ͕͍͠
ྫ֎ɾΤϥʔධՁ݁Ռͱผʹѻ͍͍ͨɺΫϥΠΞϯτଆ ͰৄࡉͳใΛࣗ༝ʹऔಘ͍ͨ͠ ͍γʔέϯεͷলུදࣔɾల։ɺϚϧνϝσ ΟΞ ը૾ ͷ 3&1-ͰͷදࣔɺΫϥΠΞϯτͷϦονͳػೳͷఏڙ ‣ ݱঢ়Ͱɺ͜ΕΒͷO3&1-Ͱղܾ͞Ε͍ͯΔ
O3&1-ͱͷҧ͍ ‣ O3&1-ೖྗߏԽ͞Εͨϝοηʔδ ϋϯυϥʹϛυϧΣΞΛՃ͢Δ͜ͱͰॲཧͰ͖Δϝο ηʔδͷछྨΛ૿͢Έ O3&1-αʔόىಈޙʹػೳΛՃ͢Δͷ͍͠ ‣ QSFQMͷೖྗ୯ͳΔϑΥʔϜ
ػೳΛՃ͠Α͏ͱࢥ͑ͦͷػೳΛ࣮ݱ͢ΔϑΥʔϜΛ ྲྀ͠ࠐΉ͚ͩ ΫϥΠΞϯτଆ͔ΒඞཁͳػೳΛ͖ͳΑ͏ʹՃͰ͖Δ l3&1-UIFVMUJNBUFDPOUFOUOFHPUJBUJPOQSPUPDPMz DG6OSFQMCMPC
͞·͟·ͳQSFQM࣮ ‣ QSFQMɿඪ४ͷQSFQM ‣ JPQSFQM ඪ४ೖग़ྗܦ༝ͰΓͱΓ͢Δ࣮ ιέοταʔό͔Βݺͼग़͞ΕΔ͜ͱΛఆ ‣
SFNPUFQSFQM ϦϞʔτͰͪड͚ΔQSFQMαʔόʹଓ͢Δ࣮
UBQ ‣ άϩʔόϧʹར༻ՄೳͳγϯϓϧͳΠϕϯτγεςϜ ‣ σόοάϩΪϯάͷ༻్Λҙਤ͍ͯ͠Δ ‣ QSFQMಋೖʹͬͯऔΓೖΕΒΕͨ
UBQͷ͍ํ ‣ add-tapremove-tapͰϋϯυϥؔΛొɾআ ‣ tap>ͰΛૹ৴ɺͯ͢ͷϋϯυϥؔͰ͕ॲཧ͞ΕΔ (defn log [x] (println “tapped
value: “ x)) (add-tap log) (tap> 1) ;; tapped value: 1 ;=> 1 (tap> 2) ;; tapped value: 2 ;=> 2 (remove-tap log) (tap> 3) ;=> 3
QSFQMͰͷUBQ ‣ UBQQSFQM্Ͱಛผʹॲཧ͞ΕΔ ‣ QSFQM্ͰσόοάϩΪϯάɺϓϩάϨεͷදࣔʹར༻ Ͱ͖Δ $ nc localhost 5555
(dotimes [i 5] (Thread/sleep 1000) (tap> i)) {:tag :tap, :val "0"} {:tag :tap, :val "1"} {:tag :tap, :val "2"} {:tag :tap, :val "3"} {:tag :tap, :val "4"} {:tag :ret, :val "nil", :ns "user", :ms 5216, :form "(dotimes [i 5] (Thread/sleep 1000) (tap> i))"}
ͦͷଞͷมߋ ‣ +7.ͷ࠷খαϙʔτόʔδϣϯมߋ ࠷খαϙʔτόʔδϣϯ͕͔Βʹ ‣ SFRVJSJOHSFTPMWF ʮ࣮ߦ࣌ʹSFRVJSFͯ͠ݺͼग़͠ʯ͕؆୯ʹॻ͚ΔΑ͏ʹ ‣
SFBE TUSJOH Ϧʔυ݁Ռͱͯ͠ݩͷจࣈྻදݱҰॹʹऔಘͰ͖Δ
·ͱΊ ‣ $MPKVSFΤϥʔϝοηʔδͷվળͱQSFQMͷՃΛத ৺ͱͨ͠มߋ ‣ ݸʑͷಠཱͨ͠ػೳͱ͍͏ΑΓɺϦονͳ։ൃڥΛ։ൃ ͢ΔͨΊͷΈΛఏڙ͢ΔͨΊͷϦϦʔεͱ͍͏ҹ ‣ 4UBZUVOFE
ࢀߟจݙ ‣ DIBOHFTNE IUUQTHJUIVCDPNDMPKVSFDMPKVSFCMPCNBTUFSDIBOHFTNE ‣ 6OSFQM IUUQTHJUIVCDPN6OSFQMVOSFQM