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
Clojureで作る"simple"なDSL
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Kent OHASHI
October 09, 2020
Programming
0
120
Clojureで作る"simple"なDSL
Clojureらしい内部DSLの開発方法について簡単に紹介。
"simple"なアプローチでDSLを作ろう!
Kent OHASHI
October 09, 2020
Tweet
Share
More Decks by Kent OHASHI
See All by Kent OHASHI
Property-Based Testing with test.check and clojure.spec
lagenorhynque
0
25
🐬の推し本紹介2025: 『コーディングを支える技術 ――成り立ちから学ぶプログラミング作法』
lagenorhynque
0
87
KotlinでミニマルなResult実装による関数型エラーハンドリング
lagenorhynque
0
39
Functional Calisthenics in Kotlin: Kotlinで「関数型エクササイズ」を実践しよう
lagenorhynque
1
340
関数型言語テイスティング: Haskell, Scala, Clojure, Elixirを比べて味わう関数型プログラミングの旨さ
lagenorhynque
1
190
純LISPから考える関数型言語のプリミティブ: Clojure, Elixir, Haskell, Scala
lagenorhynque
1
210
From Scala/Clojure to Kotlin
lagenorhynque
0
94
TDD with RDD: Clojure/LispのREPLで変わる開発体験
lagenorhynque
0
120
🐬の推し本紹介2024: 『脱・日本語なまり 英語(+α)実践音声学』
lagenorhynque
1
160
Other Decks in Programming
See All in Programming
Fundamentals of Software Engineering In the Age of AI
therealdanvega
2
260
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
190
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
300
コーディングルールの鮮度を保ちたい / keep-fresh-go-internal-conventions
handlename
0
210
ロボットのための工場に灯りは要らない
watany
10
2.9k
モックわからないマン卒業記 ~振る舞いを起点に見直した、フロントエンドテストにおけるモックの使いどころ~
tasukuwatanabe
3
390
CSC307 Lecture 15
javiergs
PRO
0
260
「やめとこ」がなくなった — 1月にZennを始めて22本書いた AI共創開発のリアル
atani14
0
400
ふつうの Rubyist、ちいさなデバイス、大きな一年
bash0c7
0
990
ベクトル検索のフィルタを用いた機械学習モデルとの統合 / python-meetup-fukuoka-06-vector-attr
monochromegane
2
470
OTP を自動で入力する裏技
megabitsenmzq
0
110
Swift ConcurrencyでよりSwiftyに
yuukiw00w
0
270
Featured
See All Featured
Ruling the World: When Life Gets Gamed
codingconduct
0
180
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
160
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.7k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Designing Experiences People Love
moore
143
24k
YesSQL, Process and Tooling at Scale
rocio
174
15k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.2k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
980
Typedesign – Prime Four
hannesfritz
42
3k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
310
Rails Girls Zürich Keynote
gr2m
96
14k
Transcript
Clojure で作る "simple" な DSL
lagénorhynque (defprofile lagénorhynque :id @lagenorhynque :reading "/laʒenɔʁɛ̃ k/" :aliases ["
カマイルカ "] :languages [Clojure Haskell English français] :interests [programming language-learning law mathematics] :commits ["github.com/lagenorhynque/duct.module.pedestal" "github.com/lagenorhynque/duct.module.cambium"] :contributes ["github.com/japan-clojurians/clojure-site-ja"])
Lisp 系⾔語で ( 内部 )DSL といえばマクロを使うもの ? マクロを定義すると コンパイル前にコード(AST) を⾃在に変換し
評価を制御することができる マクロ⾃体は rst-class object ではないので composability が損なわれる
Clojure コミュニティではマクロ定義は控えめ 「マクロ・クラブ」のルール 1. マクロを書くな 2. それがパターンをカプセル化する唯⼀の ⽅法ならば、マクロを書け cf. data
> functions > macros data-driven, data-oriented なものを好む 『プログラミングClojure 第2 版』
Clojure コミュニティでは "simple" であることを重視 ( のプレゼン) ⼀⾔でいえば、"simple" に設計しよう "simple" とは単⼀の役割/
責務のみを上 ⼿く果たすこと cf. UNIX 哲学 "complex" にするのを避けて"simple" なもの を組み合わせよう Simple Made Easy Rich Hickey
data-driven な DSL の例
のテンプレート : HTML React のJSX に相当するテンプレート Reagent (defn some-component []
[:div [:h3 "I am a component!"] [:p.someclass "I have " [:strong "bold"] [:span {:style {:color "red"}} " and red"] " text."]])
: SQL cf. ※開発予定 Salesforce のSQL ⾵⾔語 に対するDSL Honey SQL
(def sqlmap {:select [:a :b :c] :from [:foo] :where [:= :f.a "baz"]}) lagenorhynque/honeysoql SOQL
: ルーティング DSL bidi (def routes ["/" {"index.html" :index "articles/"
{"index.html" :article-index [:id "/article.html"] :article}}])
cf. : マクロベースのルーティング DSL Compojure (defroutes app (GET "/" []
"<h1>Hello World</h1>") (route/not-found "<h1>Page not found</h1>"))
: バリデーションスキーマ malli (def Address [:map [:id string?] [:tags [:set
keyword?]] [:address [:map [:street string?] [:city string?] [:zip int?] [:lonlat [:tuple double? double?]]]]])
data-driven だと何がうれしい ? Clojure でプログラム的に⾃由に操作できる ⾔語機能と標準ライブラリでそのまま扱える read (parse) も print
もそのままできる Clojure データはclojure.spec で仕様を記述で きる Clojure データとしてどのように表現し、ど のように変換/ 解釈するかだけに集中できる 問題も"simple" になる
参考 : edn 形式 Clojure リテラル( のサブセット) によるシリア ライゼーションフォーマット Clojure
にとってのS 式表現 ベクター、マップ、セットなどもある JavaScript にとってのJSON 相当 タグによる拡張も可能(extensible) Clojure とはedn 形式で表現されたデータを扱う ことに特化した⾔語ともいえる(?) edn (extensible data notation)
Further Reading Clojure/ClojureScript 関連リンク集 - Qiita Data > Functions >
Macros. But why? - LispCast