Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Clojureで作る"simple"なDSL
Search
Kent OHASHI
October 09, 2020
Programming
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Clojureで作る"simple"なDSL
Clojureらしい内部DSLの開発方法について簡単に紹介。
"simple"なアプローチでDSLを作ろう!
Kent OHASHI
October 09, 2020
More Decks by Kent OHASHI
See All by Kent OHASHI
速習FP in Scala with Flix: Flix言語で親しむ純粋関数型のコード設計
lagenorhynque
0
40
"Simple Made Easy" Made Easier: Clojureに学ぶsimplicity
lagenorhynque
0
52
Property-Based Testing with test.check and clojure.spec
lagenorhynque
0
72
🐬の推し本紹介2025: 『コーディングを支える技術 ――成り立ちから学ぶプログラミング作法』
lagenorhynque
0
140
KotlinでミニマルなResult実装による関数型エラーハンドリング
lagenorhynque
0
85
Functional Calisthenics in Kotlin: Kotlinで「関数型エクササイズ」を実践しよう
lagenorhynque
1
480
関数型言語テイスティング: Haskell, Scala, Clojure, Elixirを比べて味わう関数型プログラミングの旨さ
lagenorhynque
1
300
純LISPから考える関数型言語のプリミティブ: Clojure, Elixir, Haskell, Scala
lagenorhynque
1
330
From Scala/Clojure to Kotlin
lagenorhynque
0
140
Other Decks in Programming
See All in Programming
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
370
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
0
150
自分的「カンファレンスの楽しみ方」
syumai
0
200
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
1
290
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
660
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
240
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.5k
Family mrubyの進捗
kishima
1
110
新卒PdEのリアル
ryu1013
1
490
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
240
個人開発基盤をまるごとCloudflareに引っ越して爆速で総合的体験を向上させた話
tinykitten
0
170
XHTMLが残したもの
yosuke_furukawa
PRO
2
710
Featured
See All Featured
First, design no harm
axbom
PRO
2
1.3k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
510
Mobile First: as difficult as doing things right
swwweet
225
10k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Designing for Performance
lara
611
70k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
270
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
230
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
300
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
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