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
280
軽量デバッグツールPostmortemの紹介.pdf
athos
1
190
Clojure 1.10 概要紹介
athos
3
610
やってみる!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
(= ? (+ nREPL Docker))
athos
0
490
clojure.specの話
athos
3
2.2k
clojure.specの話(仮)
athos
2
330
Other Decks in Programming
See All in Programming
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
290
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
fs2-io を試してたらバグを見つけて直した話
chencmd
0
240
Exploring: Partial and Independent Composables
blackbracken
0
100
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
php-conference-japan-2024
tasuku43
0
320
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
140
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
360
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
380
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
40
7.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
A Philosophy of Restraint
colly
203
16k
How to Ace a Technical Interview
jacobian
276
23k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Optimizing for Happiness
mojombo
376
70k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
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