Clarifying the use of the name of the argument in s/s/d

This commit is contained in:
Jay McCarthy 2012-05-11 20:12:39 -06:00
parent 329d3bb3c8
commit 409b717ec2
23 changed files with 217 additions and 217 deletions

View File

@ -1,8 +1,8 @@
#lang scribble/doc #lang scribble/doc
@(require scribble/manual @(require scribble/manual
(for-label racket) (for-label racket
(for-label web-server/servlet) (except-in web-server/servlet make-url)
(for-label db) db)
"tutorial-util.rkt") "tutorial-util.rkt")
@(define xexpr @tech[#:doc '(lib "xml/xml.scrbl")]{X-expression}) @(define xexpr @tech[#:doc '(lib "xml/xml.scrbl")]{X-expression})
@ -1179,14 +1179,14 @@ element in the rendering code, and the name used for it in the extracting code:
@code:comment{Send an HTML page of the content of the} @code:comment{Send an HTML page of the content of the}
@code:comment{blog.} @code:comment{blog.}
(define (render-blog-page a-blog request) (define (render-blog-page a-blog request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts a-blog make-url) ,(render-posts a-blog embed/url)
(form ((action (form ((action
,(make-url insert-post-handler))) ,(embed/url insert-post-handler)))
@code:comment{"title" is used here} @code:comment{"title" is used here}
(input ((name "title"))) (input ((name "title")))
(input ((name "body"))) (input ((name "body")))
@ -1281,14 +1281,14 @@ Finally, here is how to use @racket[new-post-formlet] in @racket[render-blog-pag
@code:comment{Sends an HTML page of the content of the} @code:comment{Sends an HTML page of the content of the}
@code:comment{blog.} @code:comment{blog.}
(define (render-blog-page a-blog request) (define (render-blog-page a-blog request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts a-blog make-url) ,(render-posts a-blog embed/url)
(form ([action (form ([action
,(make-url insert-post-handler)]) ,(embed/url insert-post-handler)])
,@(formlet-display new-post-formlet) ,@(formlet-display new-post-formlet)
(input ([type "submit"]))))))) (input ([type "submit"])))))))

View File

@ -16,14 +16,14 @@
;; Produces an HTML page of the content of the ;; Produces an HTML page of the content of the
;; blog. ;; blog.
(define (render-blog-page a-blog request) (define (render-blog-page a-blog request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts a-blog make-url) ,(render-posts a-blog embed/url)
(form ((action (form ((action
,(make-url insert-post-handler))) ,(embed/url insert-post-handler)))
(input ((name "title"))) (input ((name "title")))
(input ((name "body"))) (input ((name "body")))
(input ((type "submit")))))))) (input ((type "submit"))))))))
@ -43,7 +43,7 @@
;; The user will be able to either insert new comments ;; The user will be able to either insert new comments
;; or go back to render-blog-page. ;; or go back to render-blog-page.
(define (render-post-detail-page a-blog a-post request) (define (render-post-detail-page a-blog a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Post Details")) `(html (head (title "Post Details"))
(body (body
@ -53,10 +53,10 @@
,(render-as-itemized-list ,(render-as-itemized-list
(post-comments a-post)) (post-comments a-post))
(form ((action (form ((action
,(make-url insert-comment-handler))) ,(embed/url insert-comment-handler)))
(input ((name "comment"))) (input ((name "comment")))
(input ((type "submit")))) (input ((type "submit"))))
(a ((href ,(make-url back-handler))) (a ((href ,(embed/url back-handler)))
"Back to the blog"))))) "Back to the blog")))))
(define (parse-comment bindings) (define (parse-comment bindings)
@ -82,7 +82,7 @@
;; the detail page of the post. ;; the detail page of the post.
(define (render-confirm-add-comment-page a-blog a-comment (define (render-confirm-add-comment-page a-blog a-comment
a-post request) a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Add a Comment")) `(html (head (title "Add a Comment"))
(body (body
@ -91,9 +91,9 @@
"will be added to " "will be added to "
(div ,(post-title a-post)) (div ,(post-title a-post))
(p (a ((href ,(make-url yes-handler))) (p (a ((href ,(embed/url yes-handler)))
"Yes, add the comment.")) "Yes, add the comment."))
(p (a ((href ,(make-url cancel-handler))) (p (a ((href ,(embed/url cancel-handler)))
"No, I changed my mind!")))))) "No, I changed my mind!"))))))
(define (yes-handler request) (define (yes-handler request)
@ -108,24 +108,24 @@
;; render-post: post (handler -> string) -> xexpr ;; render-post: post (handler -> string) -> xexpr
;; Consumes a post, produces an xexpr fragment of the post. ;; Consumes a post, produces an xexpr fragment of the post.
;; The fragment contains a link to show a detailed view of the post. ;; The fragment contains a link to show a detailed view of the post.
(define (render-post a-blog a-post make-url) (define (render-post a-blog a-post embed/url)
(local [(define (view-post-handler request) (local [(define (view-post-handler request)
(render-post-detail-page a-blog a-post request))] (render-post-detail-page a-blog a-post request))]
`(div ((class "post")) `(div ((class "post"))
(a ((href ,(make-url view-post-handler))) (a ((href ,(embed/url view-post-handler)))
,(post-title a-post)) ,(post-title a-post))
(p ,(post-body a-post)) (p ,(post-body a-post))
(div ,(number->string (length (post-comments a-post))) (div ,(number->string (length (post-comments a-post)))
" comment(s)")))) " comment(s)"))))
;; render-posts: blog (handler -> string) -> xexpr ;; render-posts: blog (handler -> string) -> xexpr
;; Consumes a make-url, produces an xexpr fragment ;; Consumes a embed/url, produces an xexpr fragment
;; of all its posts. ;; of all its posts.
(define (render-posts a-blog make-url) (define (render-posts a-blog embed/url)
(local [(define (render-post/make-url a-post) (local [(define (render-post/embed/url a-post)
(render-post a-blog a-post make-url))] (render-post a-blog a-post embed/url))]
`(div ((class "posts")) `(div ((class "posts"))
,@(map render-post/make-url (blog-posts a-blog))))) ,@(map render-post/embed/url (blog-posts a-blog)))))
;; render-as-itemized-list: (listof xexpr) -> xexpr ;; render-as-itemized-list: (listof xexpr) -> xexpr
;; Consumes a list of items, and produces a rendering as ;; Consumes a list of items, and produces a rendering as

View File

@ -3,11 +3,11 @@
racket/local racket/local
"../dummy-sqlite.rkt") "../dummy-sqlite.rkt")
;; A blog is a (make-blog db) ;; A blog is a (blog db)
;; where db is an sqlite database handle ;; where db is an sqlite database handle
(struct blog (db)) (struct blog (db))
;; A post is a (make-post blog id) ;; A post is a (post blog id)
;; where blog is a blog and id is an integer? ;; where blog is a blog and id is an integer?
(struct post (blog id)) (struct post (blog id))

View File

@ -1,14 +1,14 @@
#lang web-server/insta #lang web-server/insta
;; A blog is a (listof post) ;; A blog is a (listof post)
;; and a post is a (make-post title body) ;; and a post is a (post title body)
(struct post (title body)) (struct post (title body))
;; BLOG: blog ;; BLOG: blog
;; The static blog. ;; The static blog.
(define BLOG (define BLOG
(list (post "First Post" "This is my first post") (list (post "Second Post" "This is another post")
(post "Second Post" "This is another post"))) (post "First Post" "This is my first post")))
;; start: request -> response ;; start: request -> response
;; Consumes a request, and produces a page that displays all of the ;; Consumes a request, and produces a page that displays all of the

View File

@ -16,14 +16,14 @@
;; Produces an HTML page of the content of the ;; Produces an HTML page of the content of the
;; blog. ;; blog.
(define (render-blog-page a-blog request) (define (render-blog-page a-blog request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts a-blog make-url) ,(render-posts a-blog embed/url)
(form ((action (form ((action
,(make-url insert-post-handler))) ,(embed/url insert-post-handler)))
(input ((name "title"))) (input ((name "title")))
(input ((name "body"))) (input ((name "body")))
(input ((type "submit")))))))) (input ((type "submit"))))))))
@ -43,7 +43,7 @@
;; The user will be able to either insert new comments ;; The user will be able to either insert new comments
;; or go back to render-blog-page. ;; or go back to render-blog-page.
(define (render-post-detail-page a-blog a-post request) (define (render-post-detail-page a-blog a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Post Details")) `(html (head (title "Post Details"))
(body (body
@ -53,10 +53,10 @@
,(render-as-itemized-list ,(render-as-itemized-list
(post-comments a-post)) (post-comments a-post))
(form ((action (form ((action
,(make-url insert-comment-handler))) ,(embed/url insert-comment-handler)))
(input ((name "comment"))) (input ((name "comment")))
(input ((type "submit")))) (input ((type "submit"))))
(a ((href ,(make-url back-handler))) (a ((href ,(embed/url back-handler)))
"Back to the blog"))))) "Back to the blog")))))
(define (parse-comment bindings) (define (parse-comment bindings)
@ -82,7 +82,7 @@
;; the detail page of the post. ;; the detail page of the post.
(define (render-confirm-add-comment-page a-blog a-comment (define (render-confirm-add-comment-page a-blog a-comment
a-post request) a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Add a Comment")) `(html (head (title "Add a Comment"))
(body (body
@ -91,9 +91,9 @@
"will be added to " "will be added to "
(div ,(post-title a-post)) (div ,(post-title a-post))
(p (a ((href ,(make-url yes-handler))) (p (a ((href ,(embed/url yes-handler)))
"Yes, add the comment.")) "Yes, add the comment."))
(p (a ((href ,(make-url cancel-handler))) (p (a ((href ,(embed/url cancel-handler)))
"No, I changed my mind!")))))) "No, I changed my mind!"))))))
(define (yes-handler request) (define (yes-handler request)
@ -108,24 +108,24 @@
;; render-post: post (handler -> string) -> xexpr ;; render-post: post (handler -> string) -> xexpr
;; Consumes a post, produces an xexpr fragment of the post. ;; Consumes a post, produces an xexpr fragment of the post.
;; The fragment contains a link to show a detailed view of the post. ;; The fragment contains a link to show a detailed view of the post.
(define (render-post a-blog a-post make-url) (define (render-post a-blog a-post embed/url)
(local [(define (view-post-handler request) (local [(define (view-post-handler request)
(render-post-detail-page a-blog a-post request))] (render-post-detail-page a-blog a-post request))]
`(div ((class "post")) `(div ((class "post"))
(a ((href ,(make-url view-post-handler))) (a ((href ,(embed/url view-post-handler)))
,(post-title a-post)) ,(post-title a-post))
(p ,(post-body a-post)) (p ,(post-body a-post))
(div ,(number->string (length (post-comments a-post))) (div ,(number->string (length (post-comments a-post)))
" comment(s)")))) " comment(s)"))))
;; render-posts: blog (handler -> string) -> xexpr ;; render-posts: blog (handler -> string) -> xexpr
;; Consumes a make-url, produces an xexpr fragment ;; Consumes a embed/url, produces an xexpr fragment
;; of all its posts. ;; of all its posts.
(define (render-posts a-blog make-url) (define (render-posts a-blog embed/url)
(local [(define (render-post/make-url a-post) (local [(define (render-post/embed/url a-post)
(render-post a-blog a-post make-url))] (render-post a-blog a-post embed/url))]
`(div ((class "posts")) `(div ((class "posts"))
,@(map render-post/make-url (blog-posts a-blog))))) ,@(map render-post/embed/url (blog-posts a-blog)))))
;; render-as-itemized-list: (listof xexpr) -> xexpr ;; render-as-itemized-list: (listof xexpr) -> xexpr
;; Consumes a list of items, and produces a rendering as ;; Consumes a list of items, and produces a rendering as

View File

@ -25,14 +25,14 @@
;; Produces an HTML page of the content of the ;; Produces an HTML page of the content of the
;; blog. ;; blog.
(define (render-blog-page a-blog request) (define (render-blog-page a-blog request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts a-blog make-url) ,(render-posts a-blog embed/url)
(form ([action (form ([action
,(make-url insert-post-handler)]) ,(embed/url insert-post-handler)])
,@(formlet-display new-post-formlet) ,@(formlet-display new-post-formlet)
(input ([type "submit"]))))))) (input ([type "submit"])))))))
@ -54,7 +54,7 @@
;; The user will be able to either insert new comments ;; The user will be able to either insert new comments
;; or go back to render-blog-page. ;; or go back to render-blog-page.
(define (render-post-detail-page a-blog a-post request) (define (render-post-detail-page a-blog a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Post Details")) `(html (head (title "Post Details"))
(body (body
@ -64,10 +64,10 @@
,(render-as-itemized-list ,(render-as-itemized-list
(post-comments a-post)) (post-comments a-post))
(form ([action (form ([action
,(make-url insert-comment-handler)]) ,(embed/url insert-comment-handler)])
,@(formlet-display new-comment-formlet) ,@(formlet-display new-comment-formlet)
(input ([type "submit"]))) (input ([type "submit"])))
(a ([href ,(make-url back-handler)]) (a ([href ,(embed/url back-handler)])
"Back to the blog"))))) "Back to the blog")))))
(define (insert-comment-handler request) (define (insert-comment-handler request)
@ -90,7 +90,7 @@
;; the detail page of the post. ;; the detail page of the post.
(define (render-confirm-add-comment-page a-blog a-comment (define (render-confirm-add-comment-page a-blog a-comment
a-post request) a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Add a Comment")) `(html (head (title "Add a Comment"))
(body (body
@ -99,9 +99,9 @@
"will be added to " "will be added to "
(div ,(post-title a-post)) (div ,(post-title a-post))
(p (a ([href ,(make-url yes-handler)]) (p (a ([href ,(embed/url yes-handler)])
"Yes, add the comment.")) "Yes, add the comment."))
(p (a ([href ,(make-url cancel-handler)]) (p (a ([href ,(embed/url cancel-handler)])
"No, I changed my mind!")))))) "No, I changed my mind!"))))))
(define (yes-handler request) (define (yes-handler request)
@ -116,24 +116,24 @@
;; render-post: post (handler -> string) -> xexpr ;; render-post: post (handler -> string) -> xexpr
;; Consumes a post, produces an xexpr fragment of the post. ;; Consumes a post, produces an xexpr fragment of the post.
;; The fragment contains a link to show a detailed view of the post. ;; The fragment contains a link to show a detailed view of the post.
(define (render-post a-blog a-post make-url) (define (render-post a-blog a-post embed/url)
(local [(define (view-post-handler request) (local [(define (view-post-handler request)
(render-post-detail-page a-blog a-post request))] (render-post-detail-page a-blog a-post request))]
`(div ([class "post"]) `(div ([class "post"])
(a ([href ,(make-url view-post-handler)]) (a ([href ,(embed/url view-post-handler)])
,(post-title a-post)) ,(post-title a-post))
(p ,(post-body a-post)) (p ,(post-body a-post))
(div ,(number->string (length (post-comments a-post))) (div ,(number->string (length (post-comments a-post)))
" comment(s)")))) " comment(s)"))))
;; render-posts: blog (handler -> string) -> xexpr ;; render-posts: blog (handler -> string) -> xexpr
;; Consumes a make-url, produces an xexpr fragment ;; Consumes a embed/url, produces an xexpr fragment
;; of all its posts. ;; of all its posts.
(define (render-posts a-blog make-url) (define (render-posts a-blog embed/url)
(local [(define (render-post/make-url a-post) (local [(define (render-post/embed/url a-post)
(render-post a-blog a-post make-url))] (render-post a-blog a-post embed/url))]
`(div ([class "posts"]) `(div ([class "posts"])
,@(map render-post/make-url (blog-posts a-blog))))) ,@(map render-post/embed/url (blog-posts a-blog)))))
;; render-as-itemized-list: (listof xexpr) -> xexpr ;; render-as-itemized-list: (listof xexpr) -> xexpr
;; Consumes a list of items, and produces a rendering as ;; Consumes a list of items, and produces a rendering as

View File

@ -1,14 +1,14 @@
#lang web-server/insta #lang web-server/insta
;; A blog is a (listof post) ;; A blog is a (listof post)
;; and a post is a (make-post title body) ;; and a post is a (post title body)
(struct post (title body)) (struct post (title body))
;; BLOG: blog ;; BLOG: blog
;; The static blog. ;; The static blog.
(define BLOG (define BLOG
(list (post "First Post" "This is my first post") (list (post "Second Post" "This is another post")
(post "Second Post" "This is another post"))) (post "First Post" "This is my first post")))
;; start: request -> response ;; start: request -> response
;; Consumes a request and produces a page that displays all of the ;; Consumes a request and produces a page that displays all of the

View File

@ -1,14 +1,14 @@
#lang web-server/insta #lang web-server/insta
;; A blog is a (listof post) ;; A blog is a (listof post)
;; and a post is a (make-post title body) ;; and a post is a (post title body)
(struct post (title body)) (struct post (title body))
;; BLOG: blog ;; BLOG: blog
;; The static blog. ;; The static blog.
(define BLOG (define BLOG
(list (post "First Post" "This is my first post") (list (post "Second Post" "This is another post")
(post "Second Post" "This is another post"))) (post "First Post" "This is my first post")))
;; start: request -> doesn't return ;; start: request -> doesn't return
;; Consumes a request and produces a page that displays all of the ;; Consumes a request and produces a page that displays all of the
@ -26,14 +26,14 @@
;; Consumes a blog and a request, and produces an HTML page ;; Consumes a blog and a request, and produces an HTML page
;; of the content of the blog. ;; of the content of the blog.
(define (render-blog-page a-blog request) (define (render-blog-page a-blog request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts a-blog) ,(render-posts a-blog)
(form ((action (form ((action
,(make-url insert-post-handler))) ,(embed/url insert-post-handler)))
(input ((name "title"))) (input ((name "title")))
(input ((name "body"))) (input ((name "body")))
(input ((type "submit")))))))) (input ((type "submit"))))))))

View File

@ -1,10 +1,10 @@
#lang web-server/insta #lang web-server/insta
;; A blog is a (make-blog posts) ;; A blog is a (blog posts)
;; where posts is a (listof post) ;; where posts is a (listof post)
(struct blog (posts) #:mutable) (struct blog (posts) #:mutable)
;; and post is a (make-post title body) ;; and post is a (post title body)
;; where title is a string, and body is a string ;; where title is a string, and body is a string
(struct post (title body)) (struct post (title body))
@ -12,8 +12,8 @@
;; The initial BLOG. ;; The initial BLOG.
(define BLOG (define BLOG
(blog (blog
(list (post "First Post" "This is my first post") (list (post "Second Post" "This is another post")
(post "Second Post" "This is another post")))) (post "First Post" "This is my first post"))))
;; blog-insert-post!: blog post -> void ;; blog-insert-post!: blog post -> void
;; Consumes a blog and a post, adds the post at the top of the blog. ;; Consumes a blog and a post, adds the post at the top of the blog.
@ -36,14 +36,14 @@
;; render-blog-page: request -> doesn't return ;; render-blog-page: request -> doesn't return
;; Produces an HTML page of the content of the BLOG. ;; Produces an HTML page of the content of the BLOG.
(define (render-blog-page request) (define (render-blog-page request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts) ,(render-posts)
(form ((action (form ((action
,(make-url insert-post-handler))) ,(embed/url insert-post-handler)))
(input ((name "title"))) (input ((name "title")))
(input ((name "body"))) (input ((name "body")))
(input ((type "submit")))))))) (input ((type "submit"))))))))

View File

@ -1,10 +1,10 @@
#lang web-server/insta #lang web-server/insta
;; A blog is a (make-blog posts) ;; A blog is a (blog posts)
;; where posts is a (listof post) ;; where posts is a (listof post)
(struct blog (posts) #:mutable) (struct blog (posts) #:mutable)
;; and post is a (make-post title body comments) ;; and post is a (post title body comments)
;; where title is a string, body is a string, ;; where title is a string, body is a string,
;; and comments is a (listof string) ;; and comments is a (listof string)
(struct post (title body comments) #:mutable) (struct post (title body comments) #:mutable)
@ -13,12 +13,12 @@
;; The initial BLOG. ;; The initial BLOG.
(define BLOG (define BLOG
(blog (blog
(list (post "First Post" (list (post "Second Post"
"This is my first post"
(list "First comment!"))
(post "Second Post"
"This is another post" "This is another post"
(list))))) (list))
(post "First Post"
"This is my first post"
(list "First comment!")))))
;; blog-insert-post!: blog post -> void ;; blog-insert-post!: blog post -> void
;; Consumes a blog and a post, adds the post at the top of the blog. ;; Consumes a blog and a post, adds the post at the top of the blog.
@ -45,14 +45,14 @@
;; Produces an HTML page of the content of the ;; Produces an HTML page of the content of the
;; BLOG. ;; BLOG.
(define (render-blog-page request) (define (render-blog-page request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts make-url) ,(render-posts embed/url)
(form ((action (form ((action
,(make-url insert-post-handler))) ,(embed/url insert-post-handler)))
(input ((name "title"))) (input ((name "title")))
(input ((name "body"))) (input ((name "body")))
(input ((type "submit")))))))) (input ((type "submit"))))))))
@ -75,7 +75,7 @@
;; Consumes a post and request, and produces a detail page ;; Consumes a post and request, and produces a detail page
;; of the post. The user will be able to insert new comments. ;; of the post. The user will be able to insert new comments.
(define (render-post-detail-page a-post request) (define (render-post-detail-page a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Post Details")) `(html (head (title "Post Details"))
(body (body
@ -85,7 +85,7 @@
,(render-as-itemized-list ,(render-as-itemized-list
(post-comments a-post)) (post-comments a-post))
(form ((action (form ((action
,(make-url insert-comment-handler))) ,(embed/url insert-comment-handler)))
(input ((name "comment"))) (input ((name "comment")))
(input ((type "submit")))))))) (input ((type "submit"))))))))
@ -104,24 +104,24 @@
;; render-post: post (handler -> string) -> xexpr ;; render-post: post (handler -> string) -> xexpr
;; Consumes a post, produces an xexpr fragment of the post. ;; Consumes a post, produces an xexpr fragment of the post.
;; The fragment contains a link to show a detailed view of the post. ;; The fragment contains a link to show a detailed view of the post.
(define (render-post a-post make-url) (define (render-post a-post embed/url)
(local [(define (view-post-handler request) (local [(define (view-post-handler request)
(render-post-detail-page a-post request))] (render-post-detail-page a-post request))]
`(div ((class "post")) `(div ((class "post"))
(a ((href ,(make-url view-post-handler))) (a ((href ,(embed/url view-post-handler)))
,(post-title a-post)) ,(post-title a-post))
(p ,(post-body a-post)) (p ,(post-body a-post))
(div ,(number->string (length (post-comments a-post))) (div ,(number->string (length (post-comments a-post)))
" comment(s)")))) " comment(s)"))))
;; render-posts: (handler -> string) -> xexpr ;; render-posts: (handler -> string) -> xexpr
;; Consumes a make-url, and produces an xexpr fragment ;; Consumes a embed/url, and produces an xexpr fragment
;; of all its posts. ;; of all its posts.
(define (render-posts make-url) (define (render-posts embed/url)
(local [(define (render-post/make-url a-post) (local [(define (render-post/embed/url a-post)
(render-post a-post make-url))] (render-post a-post embed/url))]
`(div ((class "posts")) `(div ((class "posts"))
,@(map render-post/make-url (blog-posts BLOG))))) ,@(map render-post/embed/url (blog-posts BLOG)))))
;; render-as-itemized-list: (listof xexpr) -> xexpr ;; render-as-itemized-list: (listof xexpr) -> xexpr
;; Consumes a list of items, and produces a rendering as ;; Consumes a list of items, and produces a rendering as

View File

@ -1,10 +1,10 @@
#lang web-server/insta #lang web-server/insta
;; A blog is a (make-blog posts) ;; A blog is a (blog posts)
;; where posts is a (listof post) ;; where posts is a (listof post)
(struct blog (posts) #:mutable) (struct blog (posts) #:mutable)
;; and post is a (make-post title body comments) ;; and post is a (post title body comments)
;; where title is a string, body is a string, ;; where title is a string, body is a string,
;; and comments is a (listof string) ;; and comments is a (listof string)
(struct post (title body comments) #:mutable) (struct post (title body comments) #:mutable)
@ -13,12 +13,12 @@
;; The initial BLOG. ;; The initial BLOG.
(define BLOG (define BLOG
(blog (blog
(list (post "First Post" (list (post "Second Post"
"This is my first post"
(list "First comment!"))
(post "Second Post"
"This is another post" "This is another post"
(list))))) (list))
(post "First Post"
"This is my first post"
(list "First comment!")))))
;; blog-insert-post!: blog post -> void ;; blog-insert-post!: blog post -> void
;; Consumes a blog and a post, adds the post at the top of the blog. ;; Consumes a blog and a post, adds the post at the top of the blog.
@ -45,14 +45,14 @@
;; Produces an HTML page of the content of the ;; Produces an HTML page of the content of the
;; BLOG. ;; BLOG.
(define (render-blog-page request) (define (render-blog-page request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts make-url) ,(render-posts embed/url)
(form ((action (form ((action
,(make-url insert-post-handler))) ,(embed/url insert-post-handler)))
(input ((name "title"))) (input ((name "title")))
(input ((name "body"))) (input ((name "body")))
(input ((type "submit")))))))) (input ((type "submit"))))))))
@ -76,7 +76,7 @@
;; The user will be able to either insert new comments ;; The user will be able to either insert new comments
;; or go back to render-blog-page. ;; or go back to render-blog-page.
(define (render-post-detail-page a-post request) (define (render-post-detail-page a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Post Details")) `(html (head (title "Post Details"))
(body (body
@ -86,10 +86,10 @@
,(render-as-itemized-list ,(render-as-itemized-list
(post-comments a-post)) (post-comments a-post))
(form ((action (form ((action
,(make-url insert-comment-handler))) ,(embed/url insert-comment-handler)))
(input ((name "comment"))) (input ((name "comment")))
(input ((type "submit")))) (input ((type "submit"))))
(a ((href ,(make-url back-handler))) (a ((href ,(embed/url back-handler)))
"Back to the blog"))))) "Back to the blog")))))
(define (parse-comment bindings) (define (parse-comment bindings)
@ -113,7 +113,7 @@
;; and goes back to the display page. Otherwise, goes back to ;; and goes back to the display page. Otherwise, goes back to
;; the detail page of the post. ;; the detail page of the post.
(define (render-confirm-add-comment-page a-comment a-post request) (define (render-confirm-add-comment-page a-comment a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Add a Comment")) `(html (head (title "Add a Comment"))
(body (body
@ -122,9 +122,9 @@
"will be added to " "will be added to "
(div ,(post-title a-post)) (div ,(post-title a-post))
(p (a ((href ,(make-url yes-handler))) (p (a ((href ,(embed/url yes-handler)))
"Yes, add the comment.")) "Yes, add the comment."))
(p (a ((href ,(make-url cancel-handler))) (p (a ((href ,(embed/url cancel-handler)))
"No, I changed my mind!")))))) "No, I changed my mind!"))))))
(define (yes-handler request) (define (yes-handler request)
@ -139,24 +139,24 @@
;; render-post: post (handler -> string) -> xexpr ;; render-post: post (handler -> string) -> xexpr
;; Consumes a post, produces an xexpr fragment of the post. ;; Consumes a post, produces an xexpr fragment of the post.
;; The fragment contains a link to show a detailed view of the post. ;; The fragment contains a link to show a detailed view of the post.
(define (render-post a-post make-url) (define (render-post a-post embed/url)
(local [(define (view-post-handler request) (local [(define (view-post-handler request)
(render-post-detail-page a-post request))] (render-post-detail-page a-post request))]
`(div ((class "post")) `(div ((class "post"))
(a ((href ,(make-url view-post-handler))) (a ((href ,(embed/url view-post-handler)))
,(post-title a-post)) ,(post-title a-post))
(p ,(post-body a-post)) (p ,(post-body a-post))
(div ,(number->string (length (post-comments a-post))) (div ,(number->string (length (post-comments a-post)))
" comment(s)")))) " comment(s)"))))
;; render-posts: (handler -> string) -> xexpr ;; render-posts: (handler -> string) -> xexpr
;; Consumes a make-url, produces an xexpr fragment ;; Consumes a embed/url, produces an xexpr fragment
;; of all its posts. ;; of all its posts.
(define (render-posts make-url) (define (render-posts embed/url)
(local [(define (render-post/make-url a-post) (local [(define (render-post/embed/url a-post)
(render-post a-post make-url))] (render-post a-post embed/url))]
`(div ((class "posts")) `(div ((class "posts"))
,@(map render-post/make-url (blog-posts BLOG))))) ,@(map render-post/embed/url (blog-posts BLOG)))))
;; render-as-itemized-list: (listof xexpr) -> xexpr ;; render-as-itemized-list: (listof xexpr) -> xexpr
;; Consumes a list of items, and produces a rendering as ;; Consumes a list of items, and produces a rendering as

View File

@ -1,10 +1,10 @@
#lang web-server/insta #lang web-server/insta
;; A blog is a (make-blog posts) ;; A blog is a (blog posts)
;; where posts is a (listof post) ;; where posts is a (listof post)
(struct blog (posts) #:mutable) (struct blog (posts) #:mutable)
;; and post is a (make-post title body comments) ;; and post is a (post title body comments)
;; where title is a string, body is a string, ;; where title is a string, body is a string,
;; and comments is a (listof string) ;; and comments is a (listof string)
(struct post (title body comments) #:mutable) (struct post (title body comments) #:mutable)
@ -13,12 +13,12 @@
;; The initial BLOG. ;; The initial BLOG.
(define BLOG (define BLOG
(blog (blog
(list (post "First Post" (list (post "Second Post"
"This is my first post"
(list "First comment!"))
(post "Second Post"
"This is another post" "This is another post"
(list))))) (list))
(post "First Post"
"This is my first post"
(list "First comment!")))))
;; blog-insert-post!: blog post -> void ;; blog-insert-post!: blog post -> void
;; Consumes a blog and a post, adds the post at the top of the blog. ;; Consumes a blog and a post, adds the post at the top of the blog.
@ -45,14 +45,14 @@
;; Produces an HTML page of the content of the ;; Produces an HTML page of the content of the
;; BLOG. ;; BLOG.
(define (render-blog-page request) (define (render-blog-page request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts make-url) ,(render-posts embed/url)
(form ((action (form ((action
,(make-url insert-post-handler))) ,(embed/url insert-post-handler)))
(input ((name "title"))) (input ((name "title")))
(input ((name "body"))) (input ((name "body")))
(input ((type "submit")))))))) (input ((type "submit"))))))))
@ -76,7 +76,7 @@
;; The user will be able to either insert new comments ;; The user will be able to either insert new comments
;; or go back to render-blog-page. ;; or go back to render-blog-page.
(define (render-post-detail-page a-post request) (define (render-post-detail-page a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Post Details")) `(html (head (title "Post Details"))
(body (body
@ -86,10 +86,10 @@
,(render-as-itemized-list ,(render-as-itemized-list
(post-comments a-post)) (post-comments a-post))
(form ((action (form ((action
,(make-url insert-comment-handler))) ,(embed/url insert-comment-handler)))
(input ((name "comment"))) (input ((name "comment")))
(input ((type "submit")))) (input ((type "submit"))))
(a ((href ,(make-url back-handler))) (a ((href ,(embed/url back-handler)))
"Back to the blog"))))) "Back to the blog")))))
(define (parse-comment bindings) (define (parse-comment bindings)
@ -113,7 +113,7 @@
;; and goes back to the display page. Otherwise, goes back to ;; and goes back to the display page. Otherwise, goes back to
;; the detail page of the post. ;; the detail page of the post.
(define (render-confirm-add-comment-page a-comment a-post request) (define (render-confirm-add-comment-page a-comment a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Add a Comment")) `(html (head (title "Add a Comment"))
(body (body
@ -122,9 +122,9 @@
"will be added to " "will be added to "
(div ,(post-title a-post)) (div ,(post-title a-post))
(p (a ((href ,(make-url yes-handler))) (p (a ((href ,(embed/url yes-handler)))
"Yes, add the comment.")) "Yes, add the comment."))
(p (a ((href ,(make-url cancel-handler))) (p (a ((href ,(embed/url cancel-handler)))
"No, I changed my mind!")))))) "No, I changed my mind!"))))))
(define (yes-handler request) (define (yes-handler request)
@ -139,24 +139,24 @@
;; render-post: post (handler -> string) -> xexpr ;; render-post: post (handler -> string) -> xexpr
;; Consumes a post, produces an xexpr fragment of the post. ;; Consumes a post, produces an xexpr fragment of the post.
;; The fragment contains a link to show a detailed view of the post. ;; The fragment contains a link to show a detailed view of the post.
(define (render-post a-post make-url) (define (render-post a-post embed/url)
(local [(define (view-post-handler request) (local [(define (view-post-handler request)
(render-post-detail-page a-post request))] (render-post-detail-page a-post request))]
`(div ((class "post")) `(div ((class "post"))
(a ((href ,(make-url view-post-handler))) (a ((href ,(embed/url view-post-handler)))
,(post-title a-post)) ,(post-title a-post))
(p ,(post-body a-post)) (p ,(post-body a-post))
(div ,(number->string (length (post-comments a-post))) (div ,(number->string (length (post-comments a-post)))
" comment(s)")))) " comment(s)"))))
;; render-posts: (handler -> string) -> xexpr ;; render-posts: (handler -> string) -> xexpr
;; Consumes a make-url, produces an xexpr fragment ;; Consumes a embed/url, produces an xexpr fragment
;; of all its posts. ;; of all its posts.
(define (render-posts make-url) (define (render-posts embed/url)
(local [(define (render-post/make-url a-post) (local [(define (render-post/embed/url a-post)
(render-post a-post make-url))] (render-post a-post embed/url))]
`(div ((class "posts")) `(div ((class "posts"))
,@(map render-post/make-url (blog-posts BLOG))))) ,@(map render-post/embed/url (blog-posts BLOG)))))
;; render-as-itemized-list: (listof xexpr) -> xexpr ;; render-as-itemized-list: (listof xexpr) -> xexpr
;; Consumes a list of items, and produces a rendering as ;; Consumes a list of items, and produces a rendering as

View File

@ -12,14 +12,14 @@
;; Produces an HTML page of the content of the ;; Produces an HTML page of the content of the
;; BLOG. ;; BLOG.
(define (render-blog-page request) (define (render-blog-page request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts make-url) ,(render-posts embed/url)
(form ((action (form ((action
,(make-url insert-post-handler))) ,(embed/url insert-post-handler)))
(input ((name "title"))) (input ((name "title")))
(input ((name "body"))) (input ((name "body")))
(input ((type "submit")))))))) (input ((type "submit"))))))))
@ -43,7 +43,7 @@
;; The user will be able to either insert new comments ;; The user will be able to either insert new comments
;; or go back to render-blog-page. ;; or go back to render-blog-page.
(define (render-post-detail-page a-post request) (define (render-post-detail-page a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Post Details")) `(html (head (title "Post Details"))
(body (body
@ -53,10 +53,10 @@
,(render-as-itemized-list ,(render-as-itemized-list
(post-comments a-post)) (post-comments a-post))
(form ((action (form ((action
,(make-url insert-comment-handler))) ,(embed/url insert-comment-handler)))
(input ((name "comment"))) (input ((name "comment")))
(input ((type "submit")))) (input ((type "submit"))))
(a ((href ,(make-url back-handler))) (a ((href ,(embed/url back-handler)))
"Back to the blog"))))) "Back to the blog")))))
(define (parse-comment bindings) (define (parse-comment bindings)
@ -80,7 +80,7 @@
;; and goes back to the display page. Otherwise, goes back to ;; and goes back to the display page. Otherwise, goes back to
;; the detail page of the post. ;; the detail page of the post.
(define (render-confirm-add-comment-page a-comment a-post request) (define (render-confirm-add-comment-page a-comment a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Add a Comment")) `(html (head (title "Add a Comment"))
(body (body
@ -89,9 +89,9 @@
"will be added to " "will be added to "
(div ,(post-title a-post)) (div ,(post-title a-post))
(p (a ((href ,(make-url yes-handler))) (p (a ((href ,(embed/url yes-handler)))
"Yes, add the comment.")) "Yes, add the comment."))
(p (a ((href ,(make-url cancel-handler))) (p (a ((href ,(embed/url cancel-handler)))
"No, I changed my mind!")))))) "No, I changed my mind!"))))))
(define (yes-handler request) (define (yes-handler request)
@ -106,24 +106,24 @@
;; render-post: post (handler -> string) -> xexpr ;; render-post: post (handler -> string) -> xexpr
;; Consumes a post, produces an xexpr fragment of the post. ;; Consumes a post, produces an xexpr fragment of the post.
;; The fragment contains a link to show a detailed view of the post. ;; The fragment contains a link to show a detailed view of the post.
(define (render-post a-post make-url) (define (render-post a-post embed/url)
(local [(define (view-post-handler request) (local [(define (view-post-handler request)
(render-post-detail-page a-post request))] (render-post-detail-page a-post request))]
`(div ((class "post")) `(div ((class "post"))
(a ((href ,(make-url view-post-handler))) (a ((href ,(embed/url view-post-handler)))
,(post-title a-post)) ,(post-title a-post))
(p ,(post-body a-post)) (p ,(post-body a-post))
(div ,(number->string (length (post-comments a-post))) (div ,(number->string (length (post-comments a-post)))
" comment(s)")))) " comment(s)"))))
;; render-posts: (handler -> string) -> xexpr ;; render-posts: (handler -> string) -> xexpr
;; Consumes a make-url, produces an xexpr fragment ;; Consumes a embed/url, produces an xexpr fragment
;; of all its posts. ;; of all its posts.
(define (render-posts make-url) (define (render-posts embed/url)
(local [(define (render-post/make-url a-post) (local [(define (render-post/embed/url a-post)
(render-post a-post make-url))] (render-post a-post embed/url))]
`(div ((class "posts")) `(div ((class "posts"))
,@(map render-post/make-url (blog-posts BLOG))))) ,@(map render-post/embed/url (blog-posts BLOG)))))
;; render-as-itemized-list: (listof xexpr) -> xexpr ;; render-as-itemized-list: (listof xexpr) -> xexpr
;; Consumes a list of items, and produces a rendering as ;; Consumes a list of items, and produces a rendering as

View File

@ -16,14 +16,14 @@
;; Produces an HTML page of the content of the ;; Produces an HTML page of the content of the
;; blog. ;; blog.
(define (render-blog-page a-blog request) (define (render-blog-page a-blog request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts a-blog make-url) ,(render-posts a-blog embed/url)
(form ((action (form ((action
,(make-url insert-post-handler))) ,(embed/url insert-post-handler)))
(input ((name "title"))) (input ((name "title")))
(input ((name "body"))) (input ((name "body")))
(input ((type "submit")))))))) (input ((type "submit"))))))))
@ -43,7 +43,7 @@
;; The user will be able to either insert new comments ;; The user will be able to either insert new comments
;; or go back to render-blog-page. ;; or go back to render-blog-page.
(define (render-post-detail-page a-blog a-post request) (define (render-post-detail-page a-blog a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Post Details")) `(html (head (title "Post Details"))
(body (body
@ -53,10 +53,10 @@
,(render-as-itemized-list ,(render-as-itemized-list
(post-comments a-post)) (post-comments a-post))
(form ((action (form ((action
,(make-url insert-comment-handler))) ,(embed/url insert-comment-handler)))
(input ((name "comment"))) (input ((name "comment")))
(input ((type "submit")))) (input ((type "submit"))))
(a ((href ,(make-url back-handler))) (a ((href ,(embed/url back-handler)))
"Back to the blog"))))) "Back to the blog")))))
(define (parse-comment bindings) (define (parse-comment bindings)
@ -82,7 +82,7 @@
;; the detail page of the post. ;; the detail page of the post.
(define (render-confirm-add-comment-page a-blog a-comment (define (render-confirm-add-comment-page a-blog a-comment
a-post request) a-post request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Add a Comment")) `(html (head (title "Add a Comment"))
(body (body
@ -91,9 +91,9 @@
"will be added to " "will be added to "
(div ,(post-title a-post)) (div ,(post-title a-post))
(p (a ((href ,(make-url yes-handler))) (p (a ((href ,(embed/url yes-handler)))
"Yes, add the comment.")) "Yes, add the comment."))
(p (a ((href ,(make-url cancel-handler))) (p (a ((href ,(embed/url cancel-handler)))
"No, I changed my mind!")))))) "No, I changed my mind!"))))))
(define (yes-handler request) (define (yes-handler request)
@ -108,24 +108,24 @@
;; render-post: post (handler -> string) -> xexpr ;; render-post: post (handler -> string) -> xexpr
;; Consumes a post, produces an xexpr fragment of the post. ;; Consumes a post, produces an xexpr fragment of the post.
;; The fragment contains a link to show a detailed view of the post. ;; The fragment contains a link to show a detailed view of the post.
(define (render-post a-blog a-post make-url) (define (render-post a-blog a-post embed/url)
(local [(define (view-post-handler request) (local [(define (view-post-handler request)
(render-post-detail-page a-blog a-post request))] (render-post-detail-page a-blog a-post request))]
`(div ((class "post")) `(div ((class "post"))
(a ((href ,(make-url view-post-handler))) (a ((href ,(embed/url view-post-handler)))
,(post-title a-post)) ,(post-title a-post))
(p ,(post-body a-post)) (p ,(post-body a-post))
(div ,(number->string (length (post-comments a-post))) (div ,(number->string (length (post-comments a-post)))
" comment(s)")))) " comment(s)"))))
;; render-posts: blog (handler -> string) -> xexpr ;; render-posts: blog (handler -> string) -> xexpr
;; Consumes a make-url, produces an xexpr fragment ;; Consumes a embed/url, produces an xexpr fragment
;; of all its posts. ;; of all its posts.
(define (render-posts a-blog make-url) (define (render-posts a-blog embed/url)
(local [(define (render-post/make-url a-post) (local [(define (render-post/embed/url a-post)
(render-post a-blog a-post make-url))] (render-post a-blog a-post embed/url))]
`(div ((class "posts")) `(div ((class "posts"))
,@(map render-post/make-url (blog-posts a-blog))))) ,@(map render-post/embed/url (blog-posts a-blog)))))
;; render-as-itemized-list: (listof xexpr) -> xexpr ;; render-as-itemized-list: (listof xexpr) -> xexpr
;; Consumes a list of items, and produces a rendering as ;; Consumes a list of items, and produces a rendering as

View File

@ -16,14 +16,14 @@
;; Sends an HTML page of the content of the ;; Sends an HTML page of the content of the
;; blog. ;; blog.
(define (render-blog-page a-blog request) (define (render-blog-page a-blog request)
(define (response-generator make-url) (define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "My Blog")) `(html (head (title "My Blog"))
(body (body
(h1 "My Blog") (h1 "My Blog")
,(render-posts a-blog make-url) ,(render-posts a-blog embed/url)
(form ((action (form ((action
,(make-url insert-post-handler))) ,(embed/url insert-post-handler)))
(input ((name "title"))) (input ((name "title")))
(input ((name "body"))) (input ((name "body")))
(input ((type "submit")))))))) (input ((type "submit"))))))))
@ -43,7 +43,7 @@
;; The user will be able to either insert new comments ;; The user will be able to either insert new comments
;; or go back to render-blog-page. ;; or go back to render-blog-page.
(define (render-post-detail-page a-blog a-post request) (define (render-post-detail-page a-blog a-post request)
(define (response-generator make-url) (define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Post Details")) `(html (head (title "Post Details"))
(body (body
@ -53,10 +53,10 @@
,(render-as-itemized-list ,(render-as-itemized-list
(post-comments a-post)) (post-comments a-post))
(form ((action (form ((action
,(make-url insert-comment-handler))) ,(embed/url insert-comment-handler)))
(input ((name "comment"))) (input ((name "comment")))
(input ((type "submit")))) (input ((type "submit"))))
(a ((href ,(make-url back-handler))) (a ((href ,(embed/url back-handler)))
"Back to the blog"))))) "Back to the blog")))))
(define (parse-comment bindings) (define (parse-comment bindings)
@ -82,7 +82,7 @@
;; the detail page of the post. ;; the detail page of the post.
(define (render-confirm-add-comment-page a-blog a-comment (define (render-confirm-add-comment-page a-blog a-comment
a-post request) a-post request)
(define (response-generator make-url) (define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Add a Comment")) `(html (head (title "Add a Comment"))
(body (body
@ -91,9 +91,9 @@
"will be added to " "will be added to "
(div ,(post-title a-post)) (div ,(post-title a-post))
(p (a ((href ,(make-url yes-handler))) (p (a ((href ,(embed/url yes-handler)))
"Yes, add the comment.")) "Yes, add the comment."))
(p (a ((href ,(make-url cancel-handler))) (p (a ((href ,(embed/url cancel-handler)))
"No, I changed my mind!")))))) "No, I changed my mind!"))))))
(define (yes-handler request) (define (yes-handler request)
@ -108,26 +108,26 @@
;; render-post: post (handler -> string) -> xexpr ;; render-post: post (handler -> string) -> xexpr
;; Consumes a post, produces an xexpr fragment of the post. ;; Consumes a post, produces an xexpr fragment of the post.
;; The fragment contains a link to show a detailed view of the post. ;; The fragment contains a link to show a detailed view of the post.
(define (render-post a-blog a-post make-url) (define (render-post a-blog a-post embed/url)
(define (view-post-handler request) (define (view-post-handler request)
(render-post-detail-page a-blog a-post request)) (render-post-detail-page a-blog a-post request))
`(div ((class "post")) `(div ((class "post"))
(a ((href ,(make-url view-post-handler))) (a ((href ,(embed/url view-post-handler)))
,(post-title a-post)) ,(post-title a-post))
(p ,(post-body a-post)) (p ,(post-body a-post))
(div ,(number->string (length (post-comments a-post))) (div ,(number->string (length (post-comments a-post)))
" comment(s)"))) " comment(s)")))
;; render-posts: blog (handler -> string) -> xexpr ;; render-posts: blog (handler -> string) -> xexpr
;; Consumes a make-url, produces an xexpr fragment ;; Consumes a embed/url, produces an xexpr fragment
;; of all its posts. ;; of all its posts.
(define (render-posts a-blog make-url) (define (render-posts a-blog embed/url)
(define (render-post/make-url a-post) (define (render-post/embed/url a-post)
(render-post a-blog a-post make-url)) (render-post a-blog a-post embed/url))
`(div ((class "posts")) `(div ((class "posts"))
,@(map render-post/make-url (blog-posts a-blog)))) ,@(map render-post/embed/url (blog-posts a-blog))))
;; render-as-itemized-list: (listof xexpr) -> xexpr ;; render-as-itemized-list: (listof xexpr) -> xexpr
;; Consumes a list of items, and produces a rendering as ;; Consumes a list of items, and produces a rendering as

View File

@ -2,11 +2,11 @@
(require racket/local (require racket/local
racket/list) racket/list)
;; A blog is a (make-blog home posts) ;; A blog is a (blog home posts)
;; where home is a string, posts is a (listof post) ;; where home is a string, posts is a (listof post)
(struct blog (home posts) #:mutable #:prefab) (struct blog (home posts) #:mutable #:prefab)
;; and post is a (make-post blog title body comments) ;; and post is a (post blog title body comments)
;; where title is a string, body is a string, ;; where title is a string, body is a string,
;; and comments is a (listof string) ;; and comments is a (listof string)
(struct post (title body comments) #:mutable #:prefab) (struct post (title body comments) #:mutable #:prefab)
@ -17,12 +17,12 @@
(local [(define (log-missing-exn-handler exn) (local [(define (log-missing-exn-handler exn)
(blog (blog
(path->string home) (path->string home)
(list (post "First Post" (list (post "Second Post"
"This is my first post"
(list "First comment!"))
(post "Second Post"
"This is another post" "This is another post"
(list))))) (list))
(post "First Post"
"This is my first post"
(list "First comment!")))))
(define the-blog (define the-blog
(with-handlers ([exn? log-missing-exn-handler]) (with-handlers ([exn? log-missing-exn-handler])
(with-input-from-file home read)))] (with-input-from-file home read)))]

View File

@ -3,11 +3,11 @@
racket/local racket/local
db) db)
;; A blog is a (make-blog db) ;; A blog is a (blog db)
;; where db is an sqlite connection ;; where db is an sqlite connection
(struct blog (db)) (struct blog (db))
;; A post is a (make-post blog id) ;; A post is a (post blog id)
;; where blog is a blog and id is an integer? ;; where blog is a blog and id is an integer?
(struct post (blog id)) (struct post (blog id))

View File

@ -1,10 +1,10 @@
#lang racket/base #lang racket/base
;; A blog is a (make-blog posts) ;; A blog is a (blog posts)
;; where posts is a (listof post) ;; where posts is a (listof post)
(struct blog (posts) #:mutable) (struct blog (posts) #:mutable)
;; and post is a (make-post title body comments) ;; and post is a (post title body comments)
;; where title is a string, body is a string, ;; where title is a string, body is a string,
;; and comments is a (listof string) ;; and comments is a (listof string)
(struct post (title body comments) #:mutable) (struct post (title body comments) #:mutable)
@ -13,12 +13,12 @@
;; The initial BLOG. ;; The initial BLOG.
(define BLOG (define BLOG
(blog (blog
(list (post "First Post" (list (post "Second Post"
"This is my first post"
(list "First comment!"))
(post "Second Post"
"This is another post" "This is another post"
(list))))) (list))
(post "First Post"
"This is my first post"
(list "First comment!")))))
;; blog-insert-post!: blog post -> void ;; blog-insert-post!: blog post -> void
;; Consumes a blog and a post, adds the post at the top of the blog. ;; Consumes a blog and a post, adds the post at the top of the blog.

View File

@ -1,6 +1,6 @@
#lang web-server/insta #lang web-server/insta
;; A roster is a (make-roster names) ;; A roster is a (roster names)
;; where names is a list of string. ;; where names is a list of string.
(struct roster (names) #:mutable) (struct roster (names) #:mutable)
@ -20,14 +20,14 @@
;; show-roster: request -> doesn't return ;; show-roster: request -> doesn't return
(define (show-roster request) (define (show-roster request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Roster")) `(html (head (title "Roster"))
(body (h1 "Roster") (body (h1 "Roster")
,(render-as-itemized-list ,(render-as-itemized-list
(roster-names ROSTER)) (roster-names ROSTER))
(form ((action (form ((action
,(make-url add-name-handler))) ,(embed/url add-name-handler)))
(input ((name "a-name"))) (input ((name "a-name")))
(input ((type "submit")))))))) (input ((type "submit"))))))))
(define (parse-name bindings) (define (parse-name bindings)

View File

@ -3,12 +3,12 @@
;; start: request -> response ;; start: request -> response
(define (start request) (define (start request)
(send/suspend/dispatch (send/suspend/dispatch
(lambda (make-url) (lambda (embed/url)
(response/xexpr (response/xexpr
`(html `(html
(body (body
(a ((href ,(make-url link-1))) "Link 1") (a ((href ,(embed/url link-1))) "Link 1")
(a ((href ,(make-url link-2))) "Link 2"))))))) (a ((href ,(embed/url link-2))) "Link 2")))))))
;; link-1: request -> response ;; link-1: request -> response

View File

@ -6,11 +6,11 @@
;; show-counter: number -> doesn't return ;; show-counter: number -> doesn't return
(define (show-counter n) (define (show-counter n)
(send/suspend/dispatch (send/suspend/dispatch
(lambda (make-url) (lambda (embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Counting example")) `(html (head (title "Counting example"))
(body (body
(a ((href ,(make-url (a ((href ,(embed/url
(lambda (request) (lambda (request)
(show-counter (+ n 1)))))) (show-counter (+ n 1))))))
,(number->string n)))))))) ,(number->string n))))))))

View File

@ -1,6 +1,6 @@
#lang web-server/insta #lang web-server/insta
;; A roster is a (make-roster names) ;; A roster is a (roster names)
;; where names is a list of string. ;; where names is a list of string.
(struct roster (names) #:mutable) (struct roster (names) #:mutable)
@ -20,14 +20,14 @@
;; show-roster: request -> doesn't return ;; show-roster: request -> doesn't return
(define (show-roster request) (define (show-roster request)
(local [(define (response-generator make-url) (local [(define (response-generator embed/url)
(response/xexpr (response/xexpr
`(html (head (title "Roster")) `(html (head (title "Roster"))
(body (h1 "Roster") (body (h1 "Roster")
,(render-as-itemized-list ,(render-as-itemized-list
(roster-names ROSTER)) (roster-names ROSTER))
(form ((action (form ((action
,(make-url add-name-handler))) ,(embed/url add-name-handler)))
(input ((name "a-name"))) (input ((name "a-name")))
(input ((type "submit")))))))) (input ((type "submit"))))))))
(define (parse-name bindings) (define (parse-name bindings)

View File

@ -60,7 +60,7 @@ functions of interest for the servlet developer.
@defproc[(send/suspend/dispatch [make-response (((request? . -> . any) . -> . string?) . -> . can-be-response?)]) @defproc[(send/suspend/dispatch [make-response (((request? . -> . any) . -> . string?) . -> . can-be-response?)])
any]{ any]{
Calls @racket[make-response] with a function (@racket[embed/url]) that, when called with a procedure from Calls @racket[make-response] with a function (often named @racket[embed/url]) that, when called with a procedure from
@racket[request?] to @racket[any/c] will generate a URL, that when invoked will call @racket[request?] to @racket[any/c] will generate a URL, that when invoked will call
the function with the @racket[request?] object and return the result to the caller of the function with the @racket[request?] object and return the result to the caller of
@racket[send/suspend/dispatch]. Therefore, if you pass @racket[embed/url] the identity function, @racket[send/suspend/dispatch]. Therefore, if you pass @racket[embed/url] the identity function,