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
null or undefined
susisu
25
7.4k
Mackerel のフロントエンドフレームワーク移行 序章 / Hatena Engineer Seminar #13
susisu
0
2.1k
スクリーンショット撮影のために Puppeteer を操る / Kyoto.js 16
susisu
0
850
BuckleScript 使ってみた
susisu
0
320
Atom パッケージ開発のすゝめ
susisu
1
2.1k
5分でわかる Curry–Howard 同型対応
susisu
0
980
ジェネレータを有効活用し隊 / Kyoto.js 11 LT
susisu
2
2.1k
遅延評価と健康
susisu
0
610
楽しく学ぶ難解プログラミング言語
susisu
0
810
Other Decks in Programming
See All in Programming
RubyKaigi Dev Meeting 2025
tenderlove
1
880
監視 やばい
syossan27
12
10k
The Nature of Complexity in John Ousterhout’s Philosophy of Software Design
philipschwarz
PRO
0
150
Bedrock×MCPで社内ブログ執筆文化を育てたい!
har1101
6
1.3k
By the way Google Cloud Next 2025に行ってみてどうだった
ymd65536
0
110
Glue Studio Visual ETL実装時にハマったこと
kokitamura
1
110
エンジニア向けCursor勉強会 @ SmartHR
yukisnow1823
2
11k
Amazon CloudWatchの地味だけど強力な機能紹介!
itotsum
0
210
Exit 8 for SwiftUI
ojun9
0
150
Youtube Lofier - Chrome拡張開発
ninikoko
0
2.5k
PHP で学ぶ OAuth 入門
azuki
1
230
Ruby on Railroad: The Power of Visualizing CFG
ydah
0
270
Featured
See All Featured
Statistics for Hackers
jakevdp
798
220k
Designing for humans not robots
tammielis
253
25k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
34
2.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
178
53k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
4 Signs Your Business is Dying
shpigford
183
22k
Producing Creativity
orderedlist
PRO
344
40k
Mobile First: as difficult as doing things right
swwweet
223
9.6k
Being A Developer After 40
akosma
91
590k
The World Runs on Bad Software
bkeepers
PRO
68
11k
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
ܧ ଓ ྗ