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
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
940
useSyncExternalStoreを使いまくる
ssssota
6
1.2k
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
1.5k
nekko cloudにおけるProxmox VE利用事例
irumaru
3
440
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
400
Recoilを剥がしている話
kirik
5
6.8k
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
210
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
140
Exploring: Partial and Independent Composables
blackbracken
0
100
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
2
110
fs2-io を試してたらバグを見つけて直した話
chencmd
0
240
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
Featured
See All Featured
Become a Pro
speakerdeck
PRO
26
5k
Embracing the Ebb and Flow
colly
84
4.5k
Code Reviewing Like a Champion
maltzj
520
39k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Building an army of robots
kneath
302
44k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Agile that works and the tools we love
rasmusluckow
328
21k
How GitHub (no longer) Works
holman
311
140k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
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