File: wc-fake.rkt

package info (click to toggle)
racket 5.2.1%2Bg6~92c8784%2Bdfsg2-2%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 88,676 kB
  • sloc: ansic: 229,942; sh: 31,883; lisp: 11,486; asm: 9,970; cpp: 2,310; makefile: 2,084; pascal: 2,075; exp: 416; xml: 62; perl: 10; python: 8
file content (39 lines) | stat: -rw-r--r-- 1,498 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#lang racket
(require web-server/servlet)
(define interface-version 'v1)
(define timeout +inf.0)
(provide start interface-version timeout)

(define (start initial-request)
  (define counter1 0)
  (define counter2 0)
  (send/suspend/dispatch
   (lambda (embed/url)
     (let*-values ([(inc1 next-counter1 next-counter2) 
                    (include-counter counter1 counter2 embed/url)]
                   [(inc2 next-counter2 next-counter1)
                    (include-counter next-counter2 next-counter1 embed/url)])
       (response/xexpr
        `(html 
          (body (h2 "Web Cell Test")
                (div (h3 "First") ,(inc1 next-counter1 next-counter2))
                (div (h3 "Second") ,(inc2 next-counter2 next-counter1)))))))))

(define (include-counter my-counter other-counter embed/url)
  ; Note: This shouldn't be necessary (but is for testing, not in production)
  (call-with-current-continuation
   (lambda (k)
     (letrec ([include
               (lambda (next-my-counter next-other-counter)
                 `(div (h3 ,(number->string next-my-counter))
                       (a ([href 
                            ,(embed/url
                              (lambda _
                                (k include
                                   (add1 next-my-counter)
                                   next-other-counter)))])
                          "Increment")))])
       (values include
               my-counter
               other-counter)))
   servlet-prompt))