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.1k
Mackerel のフロントエンドフレームワーク移行 序章 / Hatena Engineer Seminar #13
susisu
0
2k
スクリーンショット撮影のために Puppeteer を操る / Kyoto.js 16
susisu
0
810
BuckleScript 使ってみた
susisu
0
290
Atom パッケージ開発のすゝめ
susisu
1
2.1k
5分でわかる Curry–Howard 同型対応
susisu
0
930
ジェネレータを有効活用し隊 / Kyoto.js 11 LT
susisu
2
2.1k
遅延評価と健康
susisu
0
580
楽しく学ぶ難解プログラミング言語
susisu
0
760
Other Decks in Programming
See All in Programming
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
事業成長を爆速で進めてきたプロダクトエンジニアたちの成功談・失敗談
nealle
3
1.4k
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
Refactor your code - refactor yourself
xosofox
1
260
バグを見つけた?それAppleに直してもらおう!
uetyo
0
170
ドメインイベント増えすぎ問題
h0r15h0
1
170
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
130
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
200
talk-with-local-llm-with-web-streams-api
kbaba1001
0
170
Featured
See All Featured
The Invisible Side of Design
smashingmag
298
50k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
GraphQLとの向き合い方2022年版
quramy
44
13k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Automating Front-end Workflow
addyosmani
1366
200k
Site-Speed That Sticks
csswizardry
2
190
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
How to Ace a Technical Interview
jacobian
276
23k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Facilitating Awesome Meetings
lara
50
6.1k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Thoughts on Productivity
jonyablonski
67
4.4k
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
ܧ ଓ ྗ