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
ここ最近のClojureScript
Search
OHTA Shogo
March 14, 2017
Programming
5
1.7k
ここ最近のClojureScript
2017/03/14に開催されたnishi-shinju-clojure #1の発表資料です。
OHTA Shogo
March 14, 2017
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
(= ? (+ nREPL Docker))
athos
0
480
clojure.specの話
athos
3
2.2k
clojure.specの話(仮)
athos
2
330
Other Decks in Programming
See All in Programming
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
110
CSC509 Lecture 11
javiergs
PRO
0
180
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
Jakarta EE meets AI
ivargrimstad
0
220
イベント駆動で成長して委員会
happymana
1
340
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.5k
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
240
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Happy Clients
brianwarren
98
6.7k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
It's Worth the Effort
3n
183
27k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
The Language of Interfaces
destraynor
154
24k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Optimizing for Happiness
mojombo
376
70k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Transcript
͜͜࠷ۙͷ ɹ$MPKVSF4DSJQU OJTIJTIJOKVDMPKVSFPO !BUIPT
ࣗݾհ ‣ 5XJUUFS!BUIPT ‣ χϟϯύεגࣜձࣾॴଐ ‣ $MPKVSFίϯτϦϏϡʔλ
͜͜࠷ۙͷ$MPKVSF$MPKVSF4DSJQU ‣ $MPKVSFք۾͕ϦϦʔε͞Εͣɺ͋·Γେ͖ͳ ಈ͖͕ͳ͍ ‣ ҰํͰɺ$MPKVSF4DSJQUͷपลΊ·͙Δ͘͠มԽ ͍ͯ͠Δ ‣ ࠓճͦͷͳ͔Ͱɺൺֱతʹେ͖ͦ͏ͩͱݸਓతʹ ࢥ͏ͷΛϐοΫΞοϓͯ͠հ
$MPKVSF4DSJQUͷେ͖ͳมԽ ‣ .BDSP*OGFSFODF ‣ &YUFSOT*OGFSFODF ‣ +4Ϟδϡʔϧαϙʔτ BMQIB ‣
ηϧϑϗετ$MPKVSF4DSJQUπʔϧଓʑొ
.BDSP*OGFSFODF ‣ $MPKVSF4DSJQUͰϚΫϩΛ$MPKVSFͰॻ͘ ‣ ͜Ε·ͰϓϩάϥϚ͕ʮͲͷࣝผࢠ͕ϚΫϩ͔ʯ Λ໌ࣔతʹίϯύΠϥʹڭ͑ͯΔඞཁ͕͋ͬͨ ‣ .BDSPJOGFSFODFʹΑΓɺίϯύΠϥ͕উखʹ Ͳͷࣝผࢠ͕ϚΫϩ͔Λࣝผͯ͘͠ΕΔΑ͏ʹ
(ns bar.core (:require-macros [foo.core :refer [add]]) (:require [foo.core :refer [subtract]]))
(add 2 3) (subtract 7 4) ͜Ε·Ͱͷίʔυ ‣ ϚΫϩ͔Ͳ͏͔Ͱ:require:require-macrosΛ͍͚Δඞཁ͋Γ ‣ bar.coreΛDMKDʹ͢Δ߹ʹSFBEFSDPOEJUJPOBM͕ඞཁ (ns foo.core) (defmacro add [a b] `(+ ~a ~b)) (ns foo.core) (defn subtract [a b] (- a b)) foo/core.clj foo/core.cljs bar/core.cljs
(ns bar.core (:require-macros [foo.core :refer [add]]) (:require [foo.core :refer [subtract]]))
(add 2 3) (subtract 7 4) ͜Ε·Ͱͷίʔυ ‣ ϚΫϩ͔Ͳ͏͔Ͱ:require:require-macrosΛ͍͚Δඞཁ͋Γ ‣ bar.coreΛDMKDʹ͢Δ߹ʹSFBEFSDPOEJUJPOBM͕ඞཁ (ns foo.core) (defmacro add [a b] `(+ ~a ~b)) (ns foo.core) (defn subtract [a b] (- a b)) foo/core.clj foo/core.cljs bar/core.cljs ϚΫϩͷ߹
(ns bar.core (:require-macros [foo.core :refer [add]]) (:require [foo.core :refer [subtract]]))
(add 2 3) (subtract 7 4) ͜Ε·Ͱͷίʔυ ‣ ϚΫϩ͔Ͳ͏͔Ͱ:require:require-macrosΛ͍͚Δඞཁ͋Γ ‣ bar.coreΛDMKDʹ͢Δ߹ʹSFBEFSDPOEJUJPOBM͕ඞཁ (ns foo.core) (defmacro add [a b] `(+ ~a ~b)) (ns foo.core) (defn subtract [a b] (- a b)) foo/core.clj foo/core.cljs bar/core.cljs ϚΫϩͷ߹ ͦΕҎ֎ͷ߹
(ns bar.core (:require [foo.core :refer [subtract] :refer-macros [add]])) (add 2
3) (subtract 7 4) ͜Ε·Ͱͷίʔυ ‣ :refer-macrosΛͬͯ:requireΛͭʹ·ͱΊΔͱଟগ͖ͬ͢Γ ‣ Կ͕ϚΫϩ͔ΛϓϩάϥϚ͕ҙ͢Δඞཁ·ͩ͋Δ (ns foo.core) (defmacro add [a b] `(+ ~a ~b)) (ns foo.core) (defn subtract [a b] (- a b)) foo/core.clj foo/core.cljs bar/core.cljs
(ns bar.core (:require [foo.core :as foo :include-macros true])) (foo/add 2
3) (foo/subtract 7 4) ͜Ε·Ͱͷίʔυ ‣ :include-macrosΛ͑Կ͕ϚΫϩ͔Λؾʹ͢Δඞཁͳ͘ͳΔ ‣ bar.coreΛDMKDʹ͢Δ߹ʹSFBEFSDPOEJUJPOBM͕ඞཁ (ns foo.core) (defmacro add [a b] `(+ ~a ~b)) (ns foo.core) (defn subtract [a b] (- a b)) foo/core.clj foo/core.cljs bar/core.cljs
(ns bar.core (:require [foo.core :refer [add subtract]])) (add 2 3)
(subtract 7 4) ͜Ε͔Β͜͏ॻ͚Δ ϚΫϩΛఆٛ͢Δ໊લۭؒଆͰҰ͓ͯ͘͠ͱɺԿ͕ ϚΫϩ͔ίϯύΠϥͰࣗಈతʹผͯ͘͠ΕΔΑ͏ʹ (ns foo.core) (defmacro add [a b] `(+ ~a ~b)) (ns foo.core (:require-macros foo.core) (defn subtract [a b] (- a b)) foo/core.clj foo/core.cljs bar/core.cljs
(ns bar.core (:require [foo.core :refer [add subtract]])) (add 2 3)
(subtract 7 4) ͜Ε͔Β͜͏ॻ͚Δ ϚΫϩΛఆٛ͢Δ໊લۭؒଆͰҰ͓ͯ͘͠ͱɺԿ͕ ϚΫϩ͔ίϯύΠϥͰࣗಈతʹผͯ͘͠ΕΔΑ͏ʹ (ns foo.core) (defmacro add [a b] `(+ ~a ~b)) (ns foo.core (:require-macros foo.core) (defn subtract [a b] (- a b)) foo/core.clj foo/core.cljs bar/core.cljs
&YUFSOT*OGFSFODF ‣ $MPKVSF4DSJQUίϯύΠϥ෦Ͱ(PPHMF$MPTVSF $PNQJMFS +4ˠ+4ͷ࠷దԽίϯύΠϥ Λ͏ ‣ $MPTVSF$PNQJMFS࠷దԽΦϓγϣϯʹΑͬͯϑΟʔ ϧυ໊ϝιου໊Λ͔ͳΓΞάϨογϒʹϦωʔϜ͢Δ ‣
֎෦ϥΠϒϥϦΛ͏߹ɺ$MPTVSF$PNQJMFS͕Β ͳ໊͍લ͕ଘࡏ͢Δͱίʔυ͕յΕΔ߹ ‣ &YUFSOT*OGFSFODFʹΑΓܕώϯτΛ͚ͭΔ͚ͩͰ໊લ ΛղܾͰ͖ΔΑ͏ʹͳͬͨ
$MPTVSF$PNQJMFSͷϦωʔϜ ίʔυΛNJOJGZ͢ΔࡍɺίϯύΠϥ͕߹ੑΛอͬͨ·· ϑΟʔϧυ໊ɾϝιου໊ΛϦωʔϜ (deftype Foo [bar baz]) (defn make-foo [bar
baz] (Foo. bar baz)) (defn area [foo] (* (.-bar foo) (.-baz foo))) function He(a,b) { return { this.xb=a; this.yb=b; } } … function Je(a,b) { return a.xb*b.yb } ClojureScript ίϯύΠϧޙJavaScript
$MPTVSF$PNQJMFSͷϦωʔϜ ίʔυΛNJOJGZ͢ΔࡍɺίϯύΠϥ͕߹ੑΛอͬͨ·· ϑΟʔϧυ໊ɾϝιου໊ΛϦωʔϜ (deftype Foo [bar baz]) (defn make-foo [bar
baz] (Foo. bar baz)) (defn area [foo] (* (.-bar foo) (.-baz foo))) function He(a,b) { return { this.xb=a; this.yb=b; } } … function Je(a,b) { return a.xb*b.yb } ClojureScript ίϯύΠϧޙJavaScript
$MPTVSF$PNQJMFSͷϦωʔϜ ίʔυΛNJOJGZ͢ΔࡍɺίϯύΠϥ͕߹ੑΛอͬͨ·· ϑΟʔϧυ໊ɾϝιου໊ΛϦωʔϜ (deftype Foo [bar baz]) (defn make-foo [bar
baz] (Foo. bar baz)) (defn area [foo] (* (.-bar foo) (.-baz foo))) function He(a,b) { return { this.xb=a; this.yb=b; } } … function Je(a,b) { return a.xb*b.yb } ClojureScript ίϯύΠϧޙJavaScript
$MPTVSF$PNQJMFSͷϦωʔϜ ίʔυΛNJOJGZ͢ΔࡍɺίϯύΠϥ͕߹ੑΛอͬͨ·· ϑΟʔϧυ໊ɾϝιου໊ΛϦωʔϜ (deftype Foo [bar baz]) (defn make-foo [bar
baz] (Foo. bar baz)) (defn area [foo] (* (.-bar foo) (.-baz foo))) function He(a,b) { return { this.xb=a; this.yb=b; } } … function Je(a,b) { return a.xb*b.yb } ClojureScript ίϯύΠϧޙJavaScript
$MPTVSF$PNQJMFSͷϦωʔϜ ίʔυΛNJOJGZ͢ΔࡍɺίϯύΠϥ͕߹ੑΛอͬͨ·· ϑΟʔϧυ໊ɾϝιου໊ΛϦωʔϜ (deftype Foo [bar baz]) (defn make-foo [bar
baz] (Foo. bar baz)) (defn area [foo] (* (.-bar foo) (.-baz foo))) function He(a,b) { return { this.xb=a; this.yb=b; } } … function Je(a,b) { return a.xb*b.yb } ClojureScript ίϯύΠϧޙJavaScript
$MPTVSF$PNQJMFSͷϦωʔϜ +4ϥΠϒϥϦΛ͏߹ίϯύΠϥ͕Βͳ໊͍લΛࢀর ͨ͠߹ʹϦωʔϜͰ߹ੑ͕ͱΕͣΤϥʔʹͳΔ͜ͱ (defn make-foo [bar baz] (js/Foo. bar baz))
(defn area [foo] (* (.-bar foo) (.-baz foo))) function Ne(a,b) { return new Foo(a,b) } … function Oe(a,b) { return a.Nb*b.Ob } ClojureScript ίϯύΠϧޙJavaScript function Foo(bar, baz) { this.bar = bar; this.baz = baz; } JavaScript
$MPTVSF$PNQJMFSͷϦωʔϜ +4ϥΠϒϥϦΛ͏߹ίϯύΠϥ͕Βͳ໊͍લΛࢀর ͨ͠߹ʹϦωʔϜͰ߹ੑ͕ͱΕͣΤϥʔʹͳΔ͜ͱ (defn make-foo [bar baz] (js/Foo. bar baz))
(defn area [foo] (* (.-bar foo) (.-baz foo))) function Ne(a,b) { return new Foo(a,b) } … function Oe(a,b) { return a.Nb*b.Ob } ClojureScript ίϯύΠϧޙJavaScript function Foo(bar, baz) { this.bar = bar; this.baz = baz; } JavaScript
ϦωʔϜͷճආࡦ ‣ FYUFSOTϑΝΠϧΛ࡞Δ $MPTVSF$PNQJMFSʹ֎෦ϥΠϒϥϦͷɹɹɹɹɹɹɹɹɹɹ ໊લΛڭ͑Δํ๏ ‣ DMKTKTϥΠϒϥϦΛ͏ FYUFSOTϑΝΠϧΛόϯυϧͨ͠+4ϥΠϒϥϦ
‣ ྻͷΠϯσΫγϯάͰ໊લʹΞΫηε agetasetΛ͏ $MPTVSF$PNQJMFSͷϦωʔϜͰจࣈྻมߋ͞Εͳ͍͜ͱΛ ར༻ var Foo = { ”bar” = {}, ”baz" = {} } externs.js
&YUFSOT*OGFSFODF ‣ &YUFSOTJOGFSFODFΛ͑ɺίϯύΠϥ͕FYUFSOT ϑΝΠϧΛࣗಈੜͯ͘͠ΕΔ ‣ ϦωʔϜ͕ʹͳΔՕॴʹܕώϯτΛ͚ͭΔ (set! *warn-on-infer* true) (defn
make-foo [bar baz] (js/Foo. bar baz)) (defn area [^js/Foo foo] (* (.-bar foo) (.-baz foo))) ClojureScript var Foo; Foo.prototype.bar; Foo.prototype.bar; inferred-externs.js ࣗಈੜʂ
+4Ϟδϡʔϧαϙʔτ BMQIB ‣ +4ʹϞδϡʔϧͷఆٛํ๏͕͍ͭ͋͘Δ $PNNPO+4 ".% &$."4DSJQU ʜ ‣
$MPKVSF4DSJQUඪ४Ͱ$MPTVSF-JCSBSZϞδϡʔϧ ͔͠ѻ͑ͳ͔ͬͨ ‣ ίϯύΠϥΦϓγϣϯͰϞδϡʔϧλΠϓΛࢦఆ͢Δ ͜ͱͰͦΕҎ֎ͷϞδϡʔϧΛ͑ΔΑ͏ʹ :foreign-libs [{:file "resources/libs/calculator.js" :provides ["calculator"] :module-type :commonjs}]
ηϧϑϗετ$MPKVSF4DSJQUπʔϧଓʑొ ‣ $MPKVSF4DSJQU͕ࣗࣗΛίϯύΠϧ ηϧϑϗεςΟϯά ɹ Ͱ͖ΔΑ͏ʹͳͬͨ͜ͱʹΑΓɺ$MPKVSFʹґଘ͠ͳ͍ॲཧܥ ͕ग़͖͍ͯͯΔ ‣ ࣮ߦʹ+7.͕ඞཁͳ͍ͷͰىಈ͕࣌ؒ͘ɺεΫϦϓτ࣮ߦ ͷ༻్ʹ͘ͷ͋Δ
‣ ॲཧܥͷྫ 1MBODL$MPKVSF4DSJQUPO+BWB4DSJQU$PSF -VNP$MPKVSF4DSJQUPO/PEFKT DBMWJO-VNP্Ͱಈ͘$MPKVSF4DSJQU༻Ϗϧυπʔϧ
͕࣌ؒ͋Ε -VNPʹ͍ͭͯܰ͘σϞ
-VNPͷಛ ‣ OQNͰαΫοͱΠϯετʔϧͰ͖Δ ‣ ىಈ͕ૣ͍ ‣ ୯ମͰ$MPKVSF4DSJQUͷϏϧυ͕Ͱ͖Δ
·ͱΊ ‣ $MPKVSF4DSJQUͷ$MPKVSF+4ʹର͢Δੑɹ ·͢·͢ߴ·͍ͬͯΔ ‣ ҰํͰɺηϧϑϗεςΟϯάʹΑΓ$MPKVSF4DSJQU ୯ମͰΤίγεςϜΛங͚ΔՄೳੑ·Ͱݟ͖͑ͯͨ ‣ $MPKVSF$MPKVSF4DSJQU ʴ+4
ͷΈ߹Θͤํɹ ࠓޙ͞Βʹଟ༷Խ͍͖ͯͦ͠͏ͳงғؾ
ࢀߟ ‣ $MPKVSF4DSJQU.BDSP4VHBS IUUQCMPHpLFTGBSNDPNQPTUTDMPKVSFTDSJQUNBDSPTVHBSIUNM .JLF'JLFT 1MBODL։ൃऀ ʹΑΔNBDSPJOGFSFODFͷղઆهࣄ ‣
&YUFSOT*OGFSFODF IUUQTHJTUHJUIVCDPNTXBOOPEFUUFGDDDDGDEBGD %BWJE/PMFOʹΑΔղઆهࣄ ‣ +BWB4DSJQU.PEVMF4VQQPSU "MQIB IUUQTHJUIVCDPNDMPKVSFDMPKVSFTDSJQUXJLJ+BWB4DSJQU.PEVMF4VQQPSU "MQIB ެࣜXJLJϖʔδ ‣ $PNQJMJOH$MPKVSF4DSJQU1SPKFDUT8JUIPVUUIF+7. IUUQTBONPOUFJSPDPNDPNQJMJOHDMPKVSFTDSJQUQSPKFDUTXJUIPVUUIFKWN "OUÓOJP/.POUFJSP -VNP։ൃऀ ʹΑΔ+7.ͳ͠Ͱͷ$MPKVSF4DSJQUͷϏϧυͷղઆهࣄ
ࢀߟ ‣ 1MBODL IUUQTHJUIVCDPNNpLFTQMBODL ‣ -VNP IUUQTHJUIVCDPNBONPOUFJSPMVNP ‣
DBMWJO IUUQTHJUIVCDPNFHJOF[DBMWJO