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
ayato
December 16, 2015
Programming
3
2.9k
ClojureScript のある生活
ayato
December 16, 2015
Tweet
Share
More Decks by ayato
See All by ayato
Clojureという言語が私逹にもたらしたもの
ayato0211
6
2.9k
3年間考え続けてきたWebアプリケーションにおけるテストの話
ayato0211
3
230
Re:REPL-Driven Development
ayato0211
3
1.2k
Meta Template Engine
ayato0211
2
1k
超変換! Hiccup data structure!!
ayato0211
2
560
About Integrant
ayato0211
0
500
Muscle Assert
ayato0211
0
220
Clojureを用いたWebアプリケーション開発
ayato0211
2
3k
翻訳にまつわるエトセトラ
ayato0211
6
1.2k
Other Decks in Programming
See All in Programming
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
2
100
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
450
Spatial Rendering for Apple Vision Pro
warrenm
0
110
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
100
fs2-io を試してたらバグを見つけて直した話
chencmd
0
240
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
210
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
110
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
480
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Mobile First: as difficult as doing things right
swwweet
222
9k
KATA
mclloyd
29
14k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Docker and Python
trallard
42
3.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
28
900
Building Your Own Lightsaber
phodgson
103
6.1k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Visualization
eitanlees
146
15k
Transcript
$MPKVSF4DSJQU ͕ ͋Δੜ׆ !@BZBUP@Q
ࣗݾհ +4Φδαϯ$MPKVSFΦδαϯ +BWB4DSJQUॳ৺ऀͰ͢ ࠓ$MPKVSF͔͠ॻ͍ͯͳ͍ਓ $ZCP[V4UBSUVQT *OD
͜Μͳܦݧ͋Γ·ͤΜ͔ʁ ྫ͑ΦϯϥΠϯγϣοϓΈ͍ͨͳγεςϜɻ
͜Μͳܦݧ͋Γ·ͤΜ͔ʁ Χʔτͷ߹ܭֹۚΛϑϩϯτΤϯυͱ αʔόʔαΠυ྆ํͰಉ͡ܭࢉΛ͢Δඞཁ͕͋Δɻ
͜Μͳܦݧ͋Γ·ͤΜ͔ʁ ͔͠͠ɺֹۚܭࢉͳͷͰͲͪΒʹ ಉ࣮͢͡Δͱ͍͏͜ͱͨ͘͠ͳ͍ɻ
͜Μͳܦݧ͋Γ·ͤΜ͔ʁ ߹ܭֹۚܭࢉ"1*Λୟ͖·ͬͯ͘ αʔόʔαΠυͰܭࢉͨ݁͠ՌΛϑϩϯτʹฦ͢
͜Μͳܦݧ͋Γ·ͤΜ͔ʁ ී௨ʹߟ͑ͯͭΒ͍ ඇಉظॲཧΛྻԽͨ͠ΓɺϝϞԽͨ͠Γେม
ͦ͜Ͱ$MPKVSF4DSJQUͰ͢Α 3FBEFS$POEJUJPOBMTͷ͓ӄͰ 8SJUFPODF SVOBOZXIFSF 5SBOTJUϑΥʔϚοτͰ γʔϜϨεͳσʔλ௨৴ ϑϩϯτΤϯυαʔόʔαΠυ $MPKVSFͷ͚ࣝͩͰॻ͚Δ
$MPKVSF4DSJQU "MU+4ͱ͍͏ΑΓ$MPKVSFͷλʔήοτ͕ +7.Ͱͳ͘+BWB4DSJQUʹͳͬͨͷ ΄ͱΜͲ$MPKVSFͱಉ͚ͩ͡ͲɺҰ෦ҧ͏ JOUFSPQͱ͔ϚΫϩ͑Δ͚Ͳॻ͚ͳ͍ͱ͔ ΤίγεςϜ͕ڧ͍ ͱͯ 'JHXIFFMͰ8FC1BDL).3ͱಉ
#SPXTFS3&1-ͰϒϥβڥऔΕΔ
3FBEFS$POEJUJPOBMT $MPKVSF͔Β͑ΔΑ͏ʹͳͬͨݴޠػೳ DMKD֦ுࢠͰఆ͓ٛͯ͘͠ͱ $MPKVSF$MPKVSF4DSJQUͲͪΒ͔ΒಡࠐՄೳ ݴޠಛ༗ͷ͚ͩΛࠩఆٛग़དྷΔ
;; dates (.getTime #?(:clj (java.util.Date.) :cljs (js/Date.))) ;; uris #?(
:clj (defn url-encode [string] (some-> string str (URLEncoder/encode "UTF-8") (.replace "+" "%20"))) :cljs (defn url-encode [string] (some-> string str (js/encodeURIComponent) (.replace "+" "%20")))) ;; reflection warnings #?(:clj (set! *warn-on-reflection* true)) 3FBEFS$POEJUJPOBMT
5SBOTJU $MPKVSFͰ༗໊ͳ$PHOJUFDUͷ࡞ͬͨ ৽͍͠σʔλϑΥʔϚοτ ϓϩάϥϜಉ࢜ͷίϛϡχέʔγϣϯʹ͑Δ ϢʔβʔఆٛܕใΛૹड৴͢Δ͜ͱ͕ग़དྷΔ ωετͨͨͩ͠ͷϚοϓྻͱάοόΠ
(ns transit-demo.core (:require [cognitect.transit :as transit]) (:import [java.io ByteArrayInputStream ByteArrayOutputStream]))
(def custom-writer (transit/write-handler-map {Cart (transit/write-handler (constantly "cart") #(:items %)) Item (transit/write-handler (constantly "item") #(apply vector (vals %)))})) (def out (ByteArrayOutputStream. 4096)) (def writer (transit/writer out :json {:handlers custom-writer})) 5SBOTJU
(defprotocol Calculatable (calculate [x])) (defrecord Cart [items] Calculatable (calculate [self]
(apply + (map calculate items)))) (defn new-cart [items] (map->Cart {:items items})) (defrecord Item [name price] Calculatable (calculate [self] (* price 1.08))) (defn new-item [name price] (map->Item {:name name, :price price})) 5SBOTJU
(def my-cart-data (new-cart [(new-item "Clojure Programming" 1000) (new-item "Clojure Applied"
2500)])) (transit/write writer my-cart-data) (.toString out) ;; => "[\"~#cart\",[[\"~#item\",[\"Clojure Programming\",1000]], ;; [\"^1\",[\"Clojure Applied\",2500]]]]" 5SBOTJU
(def custom-reader (transit/read-handler-map {"cart" (transit/read-handler new-cart) "item" (transit/read-handler #(apply new-item
%))})) (def in (ByteArrayInputStream. (.toByteArray out))) (def reader (transit/reader in :json {:handlers custom-reader})) (def my-cart-data' (transit/read reader)) (calculate my-cart-data') ;; => 3780.0 5SBOTJU
ͭ·Γ 5SBOTJU8SJUFS3FBEFS 5ZQF3FDPSE DMK DMKD DMKT 1SPUPDPM 4FSWFSTJEF $MJFOUTJEF
།Ұͷܽ 3BUJPܕ͕$MPKVSF4DSJQUͰαϙʔτ͞Εͳ͍ ϥΠϒϥϦͰղܾͰ͖ΔͷͰͳ͍
·ͱΊ 5SBOTJUϑΥʔϚοτͰγʔϜϨεʹ σʔλΛड͚ͤΔ 3FBEFS$POEJUJPOBMTͰϑϩϯτͱαʔόʔα ΠυͰඞཁͳॲཧΛڞ௨Խग़དྷΔ $MPKVSF࠷ߴʂ
Enjoy Clojure