Download - Various use of continuations in Kahua - Application in practical web programming experience
![Page 1: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/1.jpg)
1
Various use of continuations in Kahua
Applications in practical web programming experience
Katsutohi Itoh
Kahua Project
![Page 2: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/2.jpg)
2
Higher-Level APIsfor
web-applications
![Page 3: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/3.jpg)
3
Continuation for web-application
Continuation passing style is easy to write control flow on web programming.
But to write practical web applications, we want to deal with:
oIndividual components (like widgets)
![Page 4: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/4.jpg)
4
Continuation of components
How continuations of components work?
component
page -> page
component -> component?
component -> page?
component
HTML HTML HTML HTML
click hereclick here Hello,Mr.
![Page 5: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/5.jpg)
5
Start from this issue
by “Take THE Arc Challenge”http://www.paulgraham.com/arcchallenge.html
Write a program:
Produce a page with an input field & a submit button.
When input text is submitted, display an anchor link saying “click here”.
When the link is clicked, display the text posted to the first page.
![Page 6: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/6.jpg)
6
Easy to write control flow
;; said(define-entry (said) (page (form/cont/ (@@/ (cont (lambda () (let1 say (kahua-context-ref "say") (page (a/cont/ (@@/ (cont (lambda () (page (p/ "you said: " say))))) "click here")))))) (readln/ "say") (submit/))))
Call continuation procedure
Generate page
![Page 7: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/7.jpg)
7
Individual component
In practical web applications
Many components co-exist in most web pages
Want some kind of components to work individually
o ex. Something to redraw a part of page – login box embedded in page like as reddit.com, calendar as date selector at any blog site ...
Not want a component's continuation to have the whole next page
![Page 8: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/8.jpg)
8
Motivation
We want to write like this:
The “said5” has 5 individual “said” components.
;; using individual “said”(define-entry (said5) (page (map/ said '(”Alf” “Willie” “Kate” “Lynn” “Brian”))))
![Page 9: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/9.jpg)
9
How about this?
;; Does this “said” works individually?(define (said id) (form/cont/ (@@/ (cont (lambda () (let1 say (kahua-context-ref id) (a/cont/ (@@/ (cont (lambda () (p/ id " said: " say)))) "click here"))))) (readln/ id) (submit/)))
;;http://localhost/app/said5(define-entry (said5) (page (map/ said '(“Alf” “Willie” “Kate” “Lynn” “Brian”))))
Call continuation procedure
Generate page
![Page 10: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/10.jpg)
10
Diff : Said application
(define-entry (said) (page (form/cont/ (@@/ (cont (lambda () (let1 say (kahua-context-ref "say") (page (a/cont/ (@@/ (cont (lambda () (page (p/ "you said: " say))))) "click here")))))) (readln/ "say") (submit/))))
![Page 11: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/11.jpg)
11
(define-entry (said id)
(form/cont/ (@@/ (cont (lambda () (let1 say (kahua-context-ref "say")
(a/cont/ (@@/ (cont (lambda ()
(p/ id " said: " say)))) "click here"))))) (readln/ "say") (submit/)))
Diff : Said component(?)
![Page 12: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/12.jpg)
12
The problem
Continuation generates the whole page
Each component to
be independent
from the others
Expected Happened
Continuation must know the others
Continuation does not have to know the
others
![Page 13: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/13.jpg)
13
Solution : parts-cont
;; this “said” works as we expected(define (said person) (form/cont/ (@/ (id person)) ;;3 .form has the target id (@@/ (target person) ;;2 .update a target-id's node (parts-cont ;; 1.generate new node (lambda () (let1 say (kahua-context-ref person) (div/ (@/ (id person)) (a/cont/ (@@/ (target person) (parts-cont
(lambda () (p/ person " said: " say)))) "click here")))))( (readln/ person) (submit/)))
![Page 14: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/14.jpg)
14
Diff : buggy said component
(define (said person) (form/cont/ (@@/ (cont (lambda () (let1 say (kahua-context-ref person)
(a/cont/ (@@/ (cont
(lambda () (p/ person " said: " say)))) "click here"))))) (readln/ person) (submit/)))
![Page 15: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/15.jpg)
15
(define (said person) (form/cont/ (@/ (id person)) (@@/ (target person) (parts-cont (lambda () (let1 say (kahua-context-ref person) (div/ (@/ (id person)) (a/cont/ (@@/ (target person) (parts-cont
(lambda () (p/ person " said: " say)))) "click here")))))( (readln/ person) (submit/)))
Diff : parts-cont version
![Page 16: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/16.jpg)
16
What “parts-cont” does
Alf
Willie
Brian
Lynn
Kate
Input form Anchor link
Show textsubmit!
click!
form link Text
form
form
form
link
link
link
Text
Text
Text
Make each “said” to work individually
![Page 17: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/17.jpg)
17
What “parts-cont” does
body
link
text
form
link
link
html
link
Generate the whole html tree by the continuation of Brian's “said”
Alf
Willie
Kate
Lynn
Brian
head
![Page 18: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/18.jpg)
18
Mechanism : the key idea
Create continuation that generate next page by
replace target node with a new node which return from
“parts-cont” clause
![Page 19: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/19.jpg)
19
Design of the mechanism
create continuation that generate next page by replace target node with a new node which
return from “parts-cont” clause
Serverinterpreter
Continuationto generate page
Continuationto generate node
HTML tree
![Page 20: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/20.jpg)
20
More ...
The “parts-cont” mechanism highlights a new need to keep client-
side context
![Page 21: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/21.jpg)
21
Keep client-side context
;; “said” with “keep”(define (said id) (form/cont/ (@/ (id id)) (@@/ (target id) (keep #t) ;; only add keep clause (parts-cont (lambda () (let1 say (kahua-context-ref id) (div/ (@/ (id id)) (a/cont/ (@@/ (target id) (keep #t) (parts-cont
(lambda () (p/ id " said: " say)))) "click here")))))( (readln/ id) (submit/)))
![Page 22: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/22.jpg)
22
A more interesting sample
;; this “calendar/” function works as a widget of date selector.(define-entry (plan) (page (form/cont/ (@@/ (cont (entry-lambda (:keyword from to memo) (make <plan> :from from :to to :memo memo) (plan)))) (calendar/ ”from” ”Start” (current-date)) (calendar/ ”to” ”End” (current-date)) (readtext/ ”memo”) (submit/)) (map/ display/ (sort (coerce-to <list> (make-kahua-collection <plan>)) plan>=?))))
![Page 23: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/23.jpg)
23
Design of the mechanism
client-side context
Serverinterpreter
Continuationto generate pagewith keeping
client-sidecontext
Continuationto generate node
HTML tree
![Page 24: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/24.jpg)
24
Now, we have ...
The “parts-cont” mechanism, which supports individual
components.
We can write web application in smart way.
![Page 25: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/25.jpg)
25
What next?
Refine the design of “parts-cont” mechanism.
Challenge this by using partial continuation technique.
![Page 26: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/26.jpg)
26
What next?
Of course,Fix some known bugs of parts-
cont...
![Page 27: Various use of continuations in Kahua - Application in practical web programming experience](https://reader035.vdocuments.site/reader035/viewer/2022081519/5577cb6bd8b42ae0418b48de/html5/thumbnails/27.jpg)
27
Thank you