[racket] Counter servlet

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Tue Oct 12 17:47:47 EDT 2010

(a ([href ,what-you-have]) "link text")

Jay

On Tue, Oct 12, 2010 at 3:29 PM, Mark Carter <mcturra2000 at yahoo.co.uk> wrote:
> I thought I'd try to implement a stateful counter web app using DrRacket. Here's
> my code:
>
> #lang racket
>
> ;;;; define a really simply counter
>
>
> ;;; required libraries
> (require web-server/formlets
>         web-server/servlet
>         web-server/servlet-env)
>
>
> (define (counter request)
>  (let ((count 0))
>    (define (response-generator embed/url)
>      (set! count (+ 1 count))
>      `(html (head (title "Counter"))
>             (body
>              (p "Computer says: " ,(number->string count))
>              ,(embed/url (lambda (request)
>                            (counter (redirect/get))))
>              (p "Enjoy!"))))
>    (send/suspend/dispatch response-generator)))
>
>
>
> (define log-file
>  (path->string
>   (build-path (expand-user-path "~")
>               "racket-server-access.txt")))
> ; would this work better?:
> ; e.g. (list (build-path "js") (build-path "css"))
>
>
> ;;; Start the server
> (serve/servlet counter
>               #:port 8080
>               #:listen-ip #f
>               #:log-file log-file
>               #:servlet-path "/counter.rkt")
>
>
> My first question is (they'll be more in subsequent post): how do I create a
> link in the part of the code that reads
> ,(embed/url (lambda (request)
>                            (counter (redirect/get))))
>
> because so far my browser returns the text
>
> Computer says: 1/counter.rkt;((%22k%22%20.%20%22(1%201%2064623065)%22))
> Enjoy!
>
>
>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>



-- 
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.