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
outputting-beautiful-s-expression
Search
Niyarin
October 29, 2020
Programming
430
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
outputting-beautiful-s-expression
Niyarin
October 29, 2020
More Decks by Niyarin
See All by Niyarin
Scheme用nREPLの開発(エラー出力の改善)
niyarin
0
190
bel lispの紹介
niyarin
0
800
nanopass-compiler-frameworkを使ってみました
niyarin
0
510
Gorgos-parser-combinator-written-in-scheme
niyarin
0
430
Serialisp
niyarin
1
750
Mongo DBとS式検索
niyarin
0
360
goodbye-python-repl
niyarin
0
410
SchemeのEphemeronとWeak Pairの説明
niyarin
0
1.1k
red-paren-scheme-rev-macro.pdf
niyarin
0
470
Other Decks in Programming
See All in Programming
Getting Started with Vibe Coding
miccheng
0
140
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
1.8k
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
220
Event is what happens
moro
2
2.6k
AI Augmentation Techniques with Liberty
ivargrimstad
0
230
sbt 2.0: takeoff
eed3si9n
0
180
Inertia Rails: The One-Person Framework with React & Friends
skryukov
0
200
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
330
Kotlinize Is Not Just Converting to Kotlin
chigichan24
1
210
LLM 101
dalinaum
0
430
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
160
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
240
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
GraphQLとの向き合い方2022年版
quramy
50
15k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
520
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
960
Technical Leadership for Architectural Decision Making
baasie
3
620
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
[SF Ruby Conf 2025] Rails X
palkan
3
1.5k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
460
Ethics towards AI in product and experience design
skipperchong
2
450
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
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)に適用したい おしまい