[racket] Web input-string with pre-fllled value

From: Mark Carter (mcturra2000 at yahoo.co.uk)
Date: Wed Aug 25 12:20:43 EDT 2010

----- Original Message ----
> From: Jay McCarthy <jay.mccarthy at gmail.com>

> I'm interested in figuring out what is overwhelming and  alleviating
> it. Unless you're overwhelmed by its featurefullness  ;)

Yes - there's just a lot to absorb all at once. The example blog for Racket is 
very good. There's things that puzzle me, and I think it's a matter of time 
before I "get" some of the concepts involved. 

I'm starting to write up some of my findings. For example, it took me a little 
while to crack tables, and I've started to blog about it:

I've created a little VAT (Value Added Tax) calculator, which is still 
incomplete, but I have enough understanding of the framework to complete:

#lang web-server/insta

(require web-server/formlets)

(define init-input-string (λ(val)
                              (text-input #:value

(define new-post-formlet
   (div "Amount: " ,{input-string . => . amount}
        (p "")
        "VAT Rate: " ,{(init-input-string "17.5") . => . rate}
   (p "still in form"))
   (values amount rate)))

(define (render-vat-page amount rate request)
  (local [(define (response-generator make-url)
            `(html (head (title "My Calculator"))
                    (h1 "Simple VAT calculator")
                    (form ([action
                            ,(make-url insert-vat-handler)])
                          ,@(formlet-display new-post-formlet)
                          (input [(type "submit") (value "Calculate")]))
                    (p ,amount)
                    (p ,rate))))
          (define (insert-vat-handler request)
            (define-values (amount rate)
              (formlet-process new-post-formlet request))
            (print "insert-post-handle")
            (print amount)
            (render-vat-page amount rate (redirect/get)))]
    (send/suspend/dispatch response-generator)))

; start: request -> html-response
(define (start request)
  (render-vat-page "0.0" "17.5" request))

I'm a little puzzled as to whether I need the new-post-formlet needs to be 
separate from the form. I need to create a table of my results, and I'm now more 
confident as to how to do this.

I'm probably way way overambitious at this stage, but there almost seems to be a 
component model itching to get out - for example, as you might program with 
Visual Basic with an interface, state, and event code. I'm just imagining in my 
head that one could perhaps write some kind of unified model which would work 
for a web site, a traditional GUI application, or even as a console program. 
Like I say, that'd be biting off more than I can chew just now.


Posted on the users mailing list.