[plt-scheme] documentation/continue/help

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Sat Oct 25 19:48:31 EDT 2008

You think you are returning a valid Xexpr, but you are not. I have
annotated below.

On Sat, Oct 25, 2008 at 4:59 PM, maxigas <maxigas at anargeek.net> wrote:
> ;;; --- BOOT ---
>
> #lang scheme
> (require web-server/servlet)
> (provide (all-defined-out))
> (define interface-version 'v1)
> (define timeout +inf.0)
>
> ;;; --- DATA STRUCTURES ---
>
> (define-struct blog (posts) #:mutable)
>
> (define-struct post (title body comments) #:mutable)
>
> ;;; --- SAMPLE DATA ---
>
> (define BLOG (make-blog (list
>                         (make-post "Hello World!" "First post on the blog powered by a scheme engine." (list "hey" "ho" "yo"))
>                         (make-post "Hello China!" "Second post on the blog powered by a scheme engine." '()))))
>
> ;;; --- DATA HANDLERS ---
>
> (define (blog-insert-post! apost)
>  (set-blog-posts! BLOG (cons apost (blog-posts BLOG))))
>
> (define (post-insert-comment! apost acomment)
>  (set-post-comments! apost (cons acomment (post-comments apost))))
>
> ;;; --- FUNCTIONS ---
>
> (define (start request)
>  (render-blog request))
>
> ;; --- RENDERERS ---
>
> (define (render-blog request)
>  (local ((define (response-generator make-url)
>            `(html (head (title "Stratified Blog"))
>                   (body (h1 "Stratified Blog")
>                         ,(render-posts make-url request)
>                         (form ((action ,(make-url insert-post-hander)))
>                          (input ((name "title")))
>                          (input ((name "body")))
>                          (input ((type "submit")))))))
>          (define (insert-post-hander request)
>            (blog-insert-post! (parse-post (request-bindings request))
>                               (render-blog request))))
>         (send/suspend/dispatch response-generator)))
>
> (define (render-posts make-url request)
>  (local ((define (render-post/make-url apost)
>            (render-post apost make-url request)))
>         `(div ((class "posts")) (h2 "Posts") (hr)
>               ,@(map render-post/make-url (blog-posts BLOG)))))
>
> (define (render-post apost make-url request)
>  (local ((define (view-post-handler request)
>            (render-post-detail-page apost request)))
>         `(div ((class "post"))
>               (b (a ((href ,(make-url view-post-handler)) ,(post-title apost))))

Right here.

You have (a ([href ,(make-url ...)] ,(post-title ...)))

Rather than

(a ([href ,(make-url ...)]) ,(post-title ...))

An attribute list must have the form ([symbol? string?] ...)

Jay

>               (p ,(post-body apost))
>               (div ,(number->string (length (post-comments apost))))
>               " comment(s)")))
>
> (define (render-post-detail-page apost request)
>  (local ((define (response-generator make-url)
>            `(html (head (title "Post"))
>                   (body (h1 "Post")
>                         (h2 ,(post-title apost))
>                         (p ,(post-body apost))
>                         (ul ,@(map render-comments (post-comments apost)))
>                         (form ((action ,(make-url insert-comment-handler)))
>                               (input ((name "comment")))
>                               (input ((type "submit")))))))
>
>          (define (insert-comment-handler request)
>            (post-insert-comment! apost (extract-binding/single 'comment (request-bindings request)))
>            (render-post-detail-page apost request)))
>
>         (send/suspend/dispatch response-generator)))
>
> (define (render-comments acomment)
>  `(li ,acomment))
>
> ;; --- PARSERS ---
>
> (define (can-parse-post? bindings)
>  (and (exists-binding? 'title bindings) (exists-binding? 'body bindings)))
>
> (define (parse-post bindings) ; -> post
>  (if (can-parse-post? bindings)
>      (make-post (extract-binding/single 'title bindings) (extract-binding/single 'body bindings) '())
>      #f))
>
>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://jay.teammccarthy.org

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.