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.2k
Mackerel のフロントエンドフレームワーク移行 序章 / Hatena Engineer Seminar #13
susisu
0
2k
スクリーンショット撮影のために Puppeteer を操る / Kyoto.js 16
susisu
0
820
BuckleScript 使ってみた
susisu
0
300
Atom パッケージ開発のすゝめ
susisu
1
2.1k
5分でわかる Curry–Howard 同型対応
susisu
0
950
ジェネレータを有効活用し隊 / Kyoto.js 11 LT
susisu
2
2.1k
遅延評価と健康
susisu
0
590
楽しく学ぶ難解プログラミング言語
susisu
0
770
Other Decks in Programming
See All in Programming
watsonx.ai Dojo #6 継続的なAIアプリ開発と展開
oniak3ibm
PRO
0
170
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
280
Beyond ORM
77web
11
1.6k
ErdMap: Thinking about a map for Rails applications
makicamel
1
660
令和7年版 あなたが使ってよいフロントエンド機能とは
mugi_uno
10
5.2k
Scaling your build logic
antalmonori
1
100
Amazon Nova Reelの可能性
hideg
0
200
HTML/CSS超絶浅い説明
yuki0329
0
190
ecspresso, ecschedule, lambroll を PipeCDプラグインとして動かしてみた (プロトタイプ) / Running ecspresso, ecschedule, and lambroll as PipeCD Plugins (prototype)
tkikuc
2
1.9k
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
410
Lookerは可視化だけじゃない。UIコンポーネントもあるんだ!
ymd65536
1
130
Rubyでつくるパケットキャプチャツール
ydah
0
170
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
74
5.4k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
327
24k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Code Review Best Practice
trishagee
65
17k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
173
51k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
RailsConf 2023
tenderlove
29
970
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
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
ܧ ଓ ྗ