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
500
Gorgos-parser-combinator-written-in-scheme
niyarin
0
430
Serialisp
niyarin
1
740
Mongo DBとS式検索
niyarin
0
360
goodbye-python-repl
niyarin
0
400
SchemeのEphemeronとWeak Pairの説明
niyarin
0
1.1k
red-paren-scheme-rev-macro.pdf
niyarin
0
460
Other Decks in Programming
See All in Programming
The Rails Doctrine Decade
koic
2
440
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
280
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.2k
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
520
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
130
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
520
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
200
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
140
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
170
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
9.3k
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2k
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
550
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
900
Product Roadmaps are Hard
iamctodd
55
13k
How to Think Like a Performance Engineer
csswizardry
28
2.8k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
510
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.8k
How to build a perfect <img>
jonoalderson
1
6.1k
Six Lessons from altMBA
skipperchong
29
4.5k
Practical Orchestrator
shlominoach
192
12k
Skip the Path - Find Your Career Trail
mkilby
1
240
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)に適用したい おしまい