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
outputting-beautiful-s-expression
Search
Niyarin
October 29, 2020
Programming
0
380
outputting-beautiful-s-expression
Niyarin
October 29, 2020
Tweet
Share
More Decks by Niyarin
See All by Niyarin
Scheme用nREPLの開発(エラー出力の改善)
niyarin
0
150
bel lispの紹介
niyarin
0
730
nanopass-compiler-frameworkを使ってみました
niyarin
0
420
Gorgos-parser-combinator-written-in-scheme
niyarin
0
390
Serialisp
niyarin
1
660
Mongo DBとS式検索
niyarin
0
310
goodbye-python-repl
niyarin
0
360
SchemeのEphemeronとWeak Pairの説明
niyarin
0
1k
red-paren-scheme-rev-macro.pdf
niyarin
0
400
Other Decks in Programming
See All in Programming
Java on Azure で LangGraph!
kohei3110
0
170
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
190
Railsアプリケーションと パフォーマンスチューニング ー 秒間5万リクエストの モバイルオーダーシステムを支える事例 ー Rubyセミナー 大阪
falcon8823
4
950
Deep Dive into ~/.claude/projects
hiragram
8
1.5k
Elixir で IoT 開発、 Nerves なら簡単にできる!?
pojiro
1
150
Team operations that are not burdened by SRE
kazatohiei
1
210
データの民主化を支える、透明性のあるデータ利活用への挑戦 2025-06-25 Database Engineering Meetup#7
y_ken
0
320
AIコーディング道場勉強会#2 君(エンジニア)たちはどう生きるか
misakiotb
1
250
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
380
#kanrk08 / 公開版 PicoRubyとマイコンでの自作トレーニング計測装置を用いたワークアウトの理想と現実
bash0c7
1
440
FormFlow - Build Stunning Multistep Forms
yceruto
1
190
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
190
Featured
See All Featured
A better future with KSS
kneath
239
17k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
What's in a price? How to price your products and services
michaelherold
246
12k
GraphQLとの向き合い方2022年版
quramy
48
14k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
5
210
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
5.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Scaling GitHub
holman
459
140k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
Navigating Team Friction
lara
187
15k
Transcript
core.logicなどのKanren族言語を使って S式をきれいに出力したい(実験) Niyarin
S式をきれいに出力したい 割と(自分の中で)需要があったので取り組むことにした ・Schemeでマクロの展開結果を綺麗に出力したい ・Linter等のツールで綺麗にS式を出力したい 出力をある程度プログラマブルに行ないたい ・いろいろ書き方は好みがある ・インデントを変えたり ・オレオレマクロ向けに独自の改行スタイルが欲しいとか?
S式をきれいに出力する方法 ”ルール”を定義して、その範囲内で出力すればよい 例: → Kanrenなどを使ってこれを実現する ・各行は80文字以内 ・letの束縛部のインデントはそろえる ・condのペアグループを空白でわける
Kanrenとは? Logic programming用DSL (Prologみたいなことをする) SchemeのminiKanrenがオリジナル 数多くの言語に移植されており、実装がたくさんある ・core.logic (Clojure移植版) ・microKanren (40行足らずの最低限の実装、Scheme)
The reasoned Schemer 本もある → (買ったけど全部読んでいない、ごめんなさい)
core.logicの簡単な例 xは1と等しい。 xの値は? (当然1) xとyは0,1,2のどれか。xとyは等しくない。xとyの値は? (run* [x] (== x 1))
→ (1) (run* [x y] (membero x [0 1 2]) (membero y [0 1 2]) (!= x y)) → ([0 1] [1 0] [0 2] [2 0] [1 2] [2 1])
今回やったこと 小さいS式言語にインデントをつけた ・vectorで表現されるlispで、定数は、文字列と数値だけ [“list” “hello” 1 2 3] ・構文は関数適用だけ →
とはいえ、関数適用はいろいろ書き方がある (fn arg1 arg2 arg3) (fn arg1 arg2 arg3) (fn arg1 arg2 arg3) (fn arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8) (fn loooooooooooong-arg1 arg2 arg3 arg4 arg5)
与えたルール 1. 1行80文字以内 2. 引数は、インデント幅2で改行 3. OR 引数は、改行して、前の引数と同じ場所 4. OR
改行しない (fn arg1) (fn arg1 arg2) (fn arg1 arg2)
それっぽく動いた
第一引数に長い引数を与えた 80文字ルールに抵触するので、全部に改行が入った
式のネストを増やすと結果が増えすぎた それほどネストも多くないが... 50パターン出てきた
おわり パターン多すぎ、改善が必要だ! 出力数を制限する方法はあるが ☓ 良い順に整列されていない もうちょっと場合分けをいれると改善できるかも? 極力改行しない + 引数の長さで分ける
いずれは、Red-paren (私のlinter)に適用したい おしまい