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
400
outputting-beautiful-s-expression
Niyarin
October 29, 2020
Tweet
Share
More Decks by Niyarin
See All by Niyarin
Scheme用nREPLの開発(エラー出力の改善)
niyarin
0
160
bel lispの紹介
niyarin
0
750
nanopass-compiler-frameworkを使ってみました
niyarin
0
440
Gorgos-parser-combinator-written-in-scheme
niyarin
0
390
Serialisp
niyarin
1
680
Mongo DBとS式検索
niyarin
0
330
goodbye-python-repl
niyarin
0
370
SchemeのEphemeronとWeak Pairの説明
niyarin
0
1k
red-paren-scheme-rev-macro.pdf
niyarin
0
430
Other Decks in Programming
See All in Programming
フロントエンド開発のためのブラウザ組み込みAI入門
masashi
7
3.6k
AI時代に必須!状況言語化スキル / ai-context-verbalization
minodriven
2
260
GC25 Recap: The Code You Reviewed is Not the Code You Built / #newt_gophercon_tour
mazrean
0
140
Webサーバーサイド言語としてのRustについて
kouyuume
1
5k
Go言語はstack overflowの夢を見るか?
logica0419
0
670
オンデバイスAIとXcode
ryodeveloper
0
360
エンジニアインターン「Treasure」とHonoの2年、そして未来へ / Our Journey with Hono Two Years at Treasure and Beyond
carta_engineering
0
470
Claude Agent SDK を使ってみよう
hyshu
0
1.4k
モテるデスク環境
mozumasu
3
1.4k
20251016_Rails News ~Rails 8.1の足音を聴く~
morimorihoge
3
900
Amazon Verified Permissions実践入門 〜Cedar活用とAppSync導入事例/Practical Introduction to Amazon Verified Permissions
fossamagna
2
110
Register is more than clipboard
satorunooshie
1
190
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Optimizing for Happiness
mojombo
379
70k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
GitHub's CSS Performance
jonrohan
1032
470k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.7k
[RailsConf 2023] Rails as a piece of cake
palkan
57
6k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
Building a Modern Day E-commerce SEO Strategy
aleyda
44
7.9k
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)に適用したい おしまい