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
距離関数を極める! / SESSIONS 2024
gam0022
0
290
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
200
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
200
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
940
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
CSC509 Lecture 09
javiergs
PRO
0
140
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.2k
Quine, Polyglot, 良いコード
qnighy
4
650
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.3k
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
How GitHub (no longer) Works
holman
310
140k
It's Worth the Effort
3n
183
27k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Documentation Writing (for coders)
carmenintech
65
4.4k
Automating Front-end Workflow
addyosmani
1366
200k
GraphQLとの向き合い方2022年版
quramy
43
13k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
110
Side Projects
sachag
452
42k
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