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
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
6.9k
Mackerel のフロントエンドフレームワーク移行 序章 / Hatena Engineer Seminar #13
susisu
0
2k
スクリーンショット撮影のために Puppeteer を操る / Kyoto.js 16
susisu
0
800
BuckleScript 使ってみた
susisu
0
290
Atom パッケージ開発のすゝめ
susisu
1
2.1k
5分でわかる Curry–Howard 同型対応
susisu
0
910
ジェネレータを有効活用し隊 / Kyoto.js 11 LT
susisu
2
2.1k
遅延評価と健康
susisu
0
580
楽しく学ぶ難解プログラミング言語
susisu
0
740
Other Decks in Programming
See All in Programming
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
210
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
flutterkaigi_2024.pdf
kyoheig3
0
140
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Amazon Bedrock Agentsを用いてアプリ開発してみた!
har1101
0
340
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Being A Developer After 40
akosma
87
590k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
4 Signs Your Business is Dying
shpigford
180
21k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Facilitating Awesome Meetings
lara
50
6.1k
Producing Creativity
orderedlist
PRO
341
39k
Designing the Hi-DPI Web
ddemaree
280
34k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Designing for Performance
lara
604
68k
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
ܧ ଓ ྗ