[plt-scheme] Formlet problem with PLT Web Server

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Mon Aug 3 23:32:46 EDT 2009

Hi Todd,

formlet-display returns an xexpr-forest which is a list of xexprs
rather than a single xexpr

Your code use unquote (,) to include the result of formlet-display,
which results in the invalid xexpr:

(html
 (head (title "Home Page"))
 (body
  (h1 "Home Page")
  ((div () "Username:" (input ((name "input_0") (type "text")))
"Password:" (input ((name "input_1") (type "text")))))))

If you change that unquote to unquote-splicing (,@) then you are
collapsing the forest into the surrounding xexpr:

`(html (head (title "Home Page"))
        (body (h1 "Home Page")
              ,@(formlet-display login-formlet)))

with the result:

(html
 (head (title "Home Page"))
 (body
  (h1 "Home Page")
  (div () "Username:" (input ((name "input_0") (type "text")))
"Password:" (input ((name "input_1") (type "text"))))))

Hope this helps,

Jay

On Mon, Aug 3, 2009 at 9:14 PM, Todd O'Bryan<toddobryan at gmail.com> wrote:
> What am I doing wrong here? I've gotten the code down to a really
> small example, but I think I'm missing something minor.
>
> ------------------------
> #lang web-server/insta
>
> (require web-server/formlets)
>
> (define login-formlet
>  (formlet
>   (div
>    "Username:" ,{(to-string (required (text-input))) . => . username}
>    "Password:" ,{(to-string (required (password-input))) . => . password})
>   (list username password)))
>
> (define (start req)
>  `(html (head (title "Home Page"))
>         (body (h1 "Home Page")
>               ,(formlet-display login-formlet))))
> --------------------------
>
> Running this gives this error:
>
> you broke the contract xexpr? on start; Not an Xexpr. Expected a
> symbol as the element name, given (div () "Username:" (input ((name
> "input_0") (type "text"))) "Password:" (input ((name "input_1") (type
> "text"))))
>
> It looks like there's an extra () in the formlet-display result that's
> not there in the docs here:
>
> http://docs.plt-scheme.org/web-server/formlets.html#(part._.Basic_.Formlet_.Usage)
>
> Thanks,
> Todd
>
> P.S. Yes, I know I'm missing a <form> tag and all kinds of other
> stuff. I just want to see if I can display the inputs before I do all
> the rest of the stuff.
> _________________________________________________
>  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://teammccarthy.org/jay

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


Posted on the users mailing list.