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
(call/cc (lambda (cont) (cont 知見)))
Search
Susisu
October 18, 2015
Programming
0
1.1k
(call/cc (lambda (cont) (cont 知見)))
call/cc の簡単な解説と実装の適当な紹介
http://connpass.com/event/20445/
Susisu
October 18, 2015
Tweet
Share
More Decks by Susisu
See All by Susisu
君だけのオリジナル async / await を作ろう / TSKaigi 2025
susisu
18
13k
null or undefined
susisu
25
7.5k
Mackerel のフロントエンドフレームワーク移行 序章 / Hatena Engineer Seminar #13
susisu
0
2.1k
スクリーンショット撮影のために Puppeteer を操る / Kyoto.js 16
susisu
0
870
BuckleScript 使ってみた
susisu
0
330
Atom パッケージ開発のすゝめ
susisu
1
2.2k
5分でわかる Curry–Howard 同型対応
susisu
0
1k
ジェネレータを有効活用し隊 / Kyoto.js 11 LT
susisu
2
2.2k
遅延評価と健康
susisu
0
610
Other Decks in Programming
See All in Programming
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
110
コード書くの好きな人向けAIコーディング活用tips #orestudy
77web
3
300
2度もゼロから書き直して、やっとブラウザでぬるぬる動くAIに辿り着いた話
tomoino
0
160
データベースコネクションプール(DBCP)の変遷と理解
fujikawa8
1
250
AIコーディング道場勉強会#2 君(エンジニア)たちはどう生きるか
misakiotb
1
130
事業戦略を理解してソフトウェアを設計する
masuda220
PRO
22
5.9k
業務自動化をJavaとSeleniumとAWS Lambdaで実現した方法
greenflagproject
1
100
実践ArchUnit ~実例による検証パターンの紹介~
ogiwarat
2
250
UPDATEがシステムを複雑にする? イミュータブルデータモデルのすすめ
shimomura
1
530
GoのGenericsによるslice操作との付き合い方
syumai
2
490
WindowInsetsだってテストしたい
ryunen344
1
110
Development of an App for Intuitive AI Learning - Blockly Summit 2025
teba_eleven
0
110
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
71
4.9k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
Practical Orchestrator
shlominoach
188
11k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
2.8k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
60k
Making Projects Easy
brettharned
116
6.2k
4 Signs Your Business is Dying
shpigford
184
22k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
228
22k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Transcript
( c a l l / c c ( l
a m b d a ( c o n t ) ( c o n t ݟ ) ) ) 2 0 1 5 1 0 ݄ 1 8 ୈ 2 ճ O U C C LT ձ
͓ · ͑ ͔ • ͢͢͠ • ΞϨܥ • űwiűűer:
@susisu2413 • GitHub: susisu • Scheme ૉਓͰ͢
ܧ ଓ • "ܧଓʢ͚͍ͧ͘ɺcontinuationʣͱɺϓϩάϥϜͷ ࣮ߦʹ͓͍ͯ͋Δ࣌ʹ͓͍ͯධՁ͞Ε͍ͯͳ͍Γ ͷϓϩάϥϜʢthe rest of the programʣΛҙຯ͢Δ
ͷͰ͋Γɺखଓ͖ʢprocedureʣͱͯ͠දݱ͞ΕΔ ͷͰ͋Δɻ" ܧଓ - Wikipedia https://ja.wikipedia.org/wiki/ %E7%B6%99%E7%B6%9A
ࡴ െ ͱ ͠ ͨ εϥ Π υ ʹ S
ࣜ ͕ (+ 1 2)
2 ͔ Β ݟ ͨ ܧ ଓ (+ 1 (...))
ϥϜ μ ࣜ Ͱ (lambda (x) (NEXT (+ 1
x) )) NEXT ͦ͜ͰධՁΛऴྃ͢ΔԾͷॲཧ
c a l l / c c • ུͣ͞ʹݴ͏ͱ call-with-
current-continuation • ݱࡏͷܧଓΛҾͱͯ͠, ༩͑ΒΕͨؔΛݺͼग़͢ • ܧଓͨͩͷؔͳͷͰ, อଘ͓͍ͯͯ͠, ผͷॴ ͔Βݺͼग़͢͜ͱՄೳ
(+ 1 2)
2 Λ c a l l / c c ͷ
ࣜ Ͱ ஔ ͖ ͑ͯ Έ Δ (+ 1 (call/cc (lambda (cont) (cont 2)) ))
c a l l / c c ͷ Ҿ
( ؔ ) ʹ ͞ Ε Δ ܧ ଓ (+ 1 (...))
ϥϜ μ ࣜ Ͱ (lambda (x) (NEXT (+ 1
x) ))
ͭ · Γ ͜͏ ͍ ͏ ͜ ͱ (+ 1
( (lambda (cont) (cont 2)) (lambda (x) (NEXT ( (+ 1 x) ))) ))
ධ Ձ Λ ਐ Ί Δ (+ 1 (NEXT (+
1 2) ))
Կ ʹ ͑Δ ͷ ͔ • ϧʔϓग़ (break) •
ྫ֎ॲཧ (throw) • ίϧʔνϯ (yield) • return, goto, etc. • ཁಥೖͱग़
ͭΑ ͍
࣮ ͠ ͨ
Ͳ ͏ ͍ ͏ ࣮ • https://github.com/susisu/js-sandbox/blob/master/ continuation/src/v2.js •
AST ΠϯλϓϦλ in JavaScript • جૅલճͷ LT Ͱൃදͨ͠ͷͷྲྀ༻ http://susisu.hatenablog.com/entry/2015/07/12/142250 • Scheme ͷྫΛ͍͔ͭ͘ࢼͨ͠ͱ͜Ζظ௨Γʹಈ࡞ͨ͠ ͷͰɺͨͿΜ্ख͍͍ͬͯ͘Δ
ܧ ଓ ͷ ੜ ( ୯ ७ Խ ͠
ͨ ͷ ) • ࣜ Expr • ࣜͷධՁ eval : Expr → Res ― ݫີʹڥඞཁ • ධՁ݁Ռ Res = Ok Val ― ޭ | Cont Val (Res → Res) ― ܧଓ | Next Val ― ධՁऴྃ
ܧ ଓ ͷ ੜ • ྫ͑ɺෳͷࣜΛॱ൪ʹධՁ͢ΔΑ͏ͳࣜ e = (e1
: Expr, e2 : Expr, ..., eN : Expr) : Expr r = eval e, ri = eval ei ― ධՁ݁Ռ • ri = Ok v 㱺 ei+1 Ҏ߱ͷධՁΛଓ͚Δ, i = N ͳΒ r = Ok v • Cont f c 㱺 r = Cont f ((λx → eval ([r1 , ..., ri-1 ,] x, ei+1 , ..., eN )) ◦ c) • Next v 㱺 r = Next v
ܧ ଓ ͷ ੜ • τοϓϨϕϧʹதͷࣜͷධՁ݁Ռ͕ Ok v ͳΒ
Next v ͱͳΔࣜΛஔ͍͓ͯ͘ • eval “(call/cc f)” = Cont f (λx → x) • (call/cc f) ΛؚΉࣜΛධՁ͢Δͱ Cont f c ͕ಘΒΕΔ • ࠷ޙʹ c (f c) Λܭࢉ͢Ε (ͦͷ͏ͪ) ͕ग़ͯ͘Δ
?
D E M O
ܧ ଓ ྗ