[plt-scheme] Formlets in PLT

From: Michael Forster (mike at sharedlogic.ca)
Date: Thu Sep 25 11:37:09 EDT 2008

On 16-Sep-08, at 5:59 PM, Jay McCarthy wrote:

> The Links group has created formlets:
>
> http://groups.inf.ed.ac.uk/links/formlets/
>
> I have spent the afternoon implementing formlets in PLT.
> --
>


Interesting, and I'm delighted to see that PLT Scheme developers won't  
hesitate
to 'push the envelope'.

However, as a commercial developer writing and delivering applications  
with
PLT Scheme, I wonder what are the advantages of the formlet approach  
compared
to the typed interactions approach described in the HTDP extended  
exercise,
"Interacting on the Web."  Specifically, if one revises (as I have,  
snippets below)
the latter to use PLT class-based input fields to permit more  
convenient inheritance
and composition, then it, too, would seem to address the problems  
targeted by
formlets:

- static association between form and handler
- processing of raw HTML strings into structured values
- composition, involving fresh eld names at runtime


(define input%
   (class object%
     (init-field prompt)
     (init (value #f))
     (define _value value)
     (super-new)
     (define/public (generate name value)
       `(input ((name ,(symbol->string name)
                     (type "text")
                     (value ,value)))
     (define/public (extract name binding)
       (and (exists-binding? name binding)
                 (extract-binding/single name binding)))
     (define/public (type? value)
	(string? value))))

(define boolean-input%
   (class input%
    ...))

(define string-input%
   (class input%
     (init (min-length #f))
     (define _min-length min-length)
     (init (max-length #f))
     (define _max-length max-length)
     ...))

(define number-input%
   (class input%
     (init (min-value #f))
     (define _min-value min-value)
     (init (max-value #f))
     (define _max-value max-value)
     ...))

(define decimal-input%
   (class number-input%
    ...))

(define calendar-date-input%
   (class input%
    ...))

...

(define (query names-and-inputs
                            #:title (title "Query")
                            #:form-generator (form-generator standard- 
form-generator)
                            #:submit-buttons (submit-buttons (list  
"OK"))
                            #:cancel-button (cancel-button "Cancel"))
   ...)


--
Michael Forster
mike at sharedlogic.ca





Posted on the users mailing list.