

cout << "First number: " cin >> x; cout << "Second number: " cin >> y; sum = x + y; cout << "Result: " + sum << endl;
(define (start req)
(let ((num1 (send-and-get "First number"))
(num2 (send-and-get "Second number")))
(mk-result-page (+ num1 num2))))
send-and-get
intstart procedureresponse/xexpr for turning list into HTML
#lang web-server/insta
(define (start request)
(response/xexpr
'(html
(head (title "My App"))
(body (h1 "Under construction")))))
` is like ' but you can insert Scheme code inside, adds a Scheme value (which can contain nested
`),@ splices in a list of Scheme values(define (mk-result-page x)
(response/xexpr
`(html
(body
"Result: "
,(number->string x))))))
send/suspend(send/suspend
(λ (k-url)
(response/xexpr
`(html (head (title "Enter a number"))
(body
(form ([action, k-url]) ; Set URL for action attribute
"Enter a number: "
(input ((type "text") (name "num")))
(input ((type "submit")))))))))
(define (send-and-get msg)
(string->number
(extract-binding/single
'num
(request-bindings
(send/suspend (λ (k-url) ...))))))
send/suspendlet/cc is a delimited continuation, denoting the
“rest of the computation” until a demarcation defined (in
Racket) by promptabort returns to the nearest promptprompt into the dispatch loop
(define (send/suspend mk-page)
(let/cc k
(define tag (format "k~a" (current-inexact-milliseconds)))
(hash-set! dispatch-table tag k)
(abort (mk-page (string-append "/" tag)))))
send/suspend/dispatchsend/suspend's page function gets an URL for continuingsend/suspend/dispatch provides a link-making function that
you use to encode multiple links(define (mk-count i)
(send/suspend/dispatch
(λ (make-url)
(response/xexpr
`(html (head (title "Count!"))
(body
(a ((href ,(make-url (λ (req) (mk-count (sub1 i)))))) "-")
,(number->string i)
(a ((href ,(make-url (λ (req) (mk-count (add1 i)))))) "+")))))))

#lang web-server/insta
(define (start request)
(response/xexpr
'(html
(head (title "My Web App"))
(body (h1 "Under construction")))))
What happens?
http://google.com. What is the code of your web app?(mk-number-page prompt url) that generates the
Scheme code for
<html><head><title>Prompt</title> <body><form action="URL"> Prompt<input type="text" name="num"/> <input type="submit"/></form></body></html>
Test your code in the bottom pane.
What is your function?
(send-and-get prompt) that can be used as
(let ((num1 (send-and-get "First number")) ...
response/xexpr to turn the Scheme HTML
from mk-number-page to real HTMLsend/suspend to wait for the responsenum attribute value from the response as
shown in the lecture's sample codeWhat is your function?
start
function of your web application. What is the code of the
start function?
(define (mk-result-page x) `(html (body "Result: " ,(number->string x))))
send/suspend/dispatch to make an URLmk-result-page needs to make an (a ((href ...))
"Start over")mk-result-page(define (show-sum req) ; We ignore the request
(send/suspend/dispatch
(λ (make-url)
(let ((num1 ...) (num2 ...))
(response/xexpr (mk-result-page (+ num1 num2) make-url))))))
startWhat is your program now?