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
290
軽量デバッグツールPostmortemの紹介.pdf
athos
1
190
Clojure 1.10 概要紹介
athos
3
610
やってみる!clojure.spec
athos
4
980
kitchen-async: a promising (?) Promise library, or a poor man's core.async
athos
3
430
Clojure 1.9 概要紹介
athos
4
1.4k
(= ? (+ nREPL Docker))
athos
0
500
clojure.specの話
athos
3
2.2k
clojure.specの話(仮)
athos
2
340
Other Decks in Programming
See All in Programming
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
630
Rubyでつくるパケットキャプチャツール
ydah
0
170
Fibonacci Function Gallery - Part 2
philipschwarz
PRO
0
210
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
280
return文におけるstd::moveについて
onihusube
1
1.4k
Amazon Nova Reelの可能性
hideg
0
200
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
1.4k
React 19でお手軽にCSS-in-JSを自作する
yukukotani
5
570
php-conference-japan-2024
tasuku43
0
430
Jaspr Dart Web Framework 박제창 @Devfest 2024
itsmedreamwalker
0
150
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
2
7.7k
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
430
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
How GitHub (no longer) Works
holman
312
140k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.5k
The Invisible Side of Design
smashingmag
299
50k
How to Ace a Technical Interview
jacobian
276
23k
BBQ
matthewcrist
85
9.4k
Rails Girls Zürich Keynote
gr2m
94
13k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Scaling GitHub
holman
459
140k
GitHub's CSS Performance
jonrohan
1030
460k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Done Done
chrislema
182
16k
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