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
Golangで小さなLispインタプリタを作ってみた
Search
Takuro Niitsuma
December 25, 2017
Programming
0
160
Golangで小さなLispインタプリタを作ってみた
昔の社内勉強会で作ったスライド。GitPitchが閉鎖してたため移行。
Takuro Niitsuma
December 25, 2017
Tweet
Share
More Decks by Takuro Niitsuma
See All by Takuro Niitsuma
ウェブ・ソーシャルメディア論文読み会 - Machine-Made Media: Monitoring the Mobilization of Machine-Generated Articles on Misinformation and Mainstream News Websites
otakumesi
0
84
Reactでライフゲームを作ってみた話
otakumesi
0
120
Other Decks in Programming
See All in Programming
Goで作る、開発・CI環境
sin392
0
230
Webの外へ飛び出せ NativePHPが切り拓くPHPの未来
takuyakatsusa
2
560
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
570
iOS 26にアップデートすると実機でのHot Reloadができない?
umigishiaoi
0
130
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
3
770
システム成長を止めない!本番無停止テーブル移行の全貌
sakawe_ee
1
200
たった 1 枚の PHP ファイルで実装する MCP サーバ / MCP Server with Vanilla PHP
okashoi
1
260
AI コーディングエージェントの時代へ:JetBrains が描く開発の未来
masaruhr
1
160
レベル1の開発生産性向上に取り組む − 日々の作業の効率化・自動化を通じた改善活動
kesoji
0
220
Quand Symfony, ApiPlatform, OpenAI et LangChain s'allient pour exploiter vos PDF : de la théorie à la production…
ahmedbhs123
0
190
なんとなくわかった気になるブロックテーマ入門/contents.nagoya 2025 6.28
chiilog
1
270
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
390
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.9k
Embracing the Ebb and Flow
colly
86
4.7k
Designing for Performance
lara
610
69k
How STYLIGHT went responsive
nonsquared
100
5.6k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
GitHub's CSS Performance
jonrohan
1031
460k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
A Tale of Four Properties
chriscoyier
160
23k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
The Cult of Friendly URLs
andyhume
79
6.5k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Transcript
Golangで 小さなLispインタプリタ を作ってみた 0x64物語 Reboot #09 @otakumesi
@otakumesi マッハバイトでエンジニアしてます。
みなさん、木といったらなにを思い浮かべますか?
クリスマスツリー、木構造、二分木、...
Lisp
Lisp カッコが多いとかで敬遠されがちな言語 マスコットキャラのLispエイリアンが可愛い Haskell共和国と戦争中らしい(某書によると) LISt Processorを略した名称に由来
Lispエイリアン
Lispの構文は木構造 簡単なLispのコードを見てみましょう。 (+ (* 1 (+ 3 4)) (- 5
(/ 10 5))) ;; => 10
Lispの構文は木構造 ちゃんとインデントをつけてみてみると、 木構造に見えてきませんか? (+ (* 1 (+ 3 4)) (-
5 (/ 10 5))) ;; => 10
Lispの構文は木構造 Lispの構文のS式はそのまま構文木になります (+ (*1 (+34)) (-5 (/105)));; =>10 + /
\ * - / \ / \ 1 + 5 ÷ / \ / \ 3 4 10 5
GolangでLispを 実装した話
動機 Golangで挑戦できるいい題材を探してた (元)Emacs使いとしての目標の一つだった 0x64物語のお題が「木」だった
デモ(REPL) https://github.com/otakumesi/lispon
最初の発想 「Lispは木構造なので、S式の頂点から要素を再帰的に評価していけば、葉までたどり着いて 結果を返せそう」
ゆるふわなクラス図
反省 初期実装を勢いで書いたため「純LISP」の仕様の確認が遅くなった そして「カッコがいっぱいあるだけでLispじゃなくね?」と気がついて、途中でそ れなりに書き直した 未だにLispの仕様がゆるふわ...... Compositeパターンを意識して書いたらもう少しキレイな設計になった気がする
開発中にGolangに対して思ったこと メソッドオーバーロード欲しい オプション引数欲しい (生粋のGopherさんにマサカリ投げられそう)
引き算された言語機能が欲しいと思うこともあったが... Golangを書いてるとなぜだか心地よくなってきて、そんなことどうでもよくなりました (?)
そして、Golangのオプション引数の解決策が面白くて好きです
オプション引数の代替 FunctionalOptionPatternを使って解決した type Option func(*Sexpr)error func Rhs(rhs Evaler)error { return
func(*Sexpr)error { return s.SetRhs(rhs) } } func NewSexpr(opts ...Option) { ... }
せっかくなのでHTMLを書いてみた
GolangでLispをテンプレートエンジンっぽく使って LambdaからHelloWorldした図(?)
これをツイートしたらmattnさんに、 こんなコメントを貰えたので僕は満足しました
終わり