File: wc-fake.rkt

package info (click to toggle)
racket 7.9%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 178,684 kB
  • sloc: ansic: 282,112; lisp: 234,887; pascal: 70,954; sh: 27,112; asm: 16,268; makefile: 4,613; cpp: 2,715; ada: 1,681; javascript: 1,244; cs: 879; exp: 499; csh: 422; python: 274; xml: 106; perl: 104
file content (33 lines) | stat: -rw-r--r-- 1,311 bytes parent folder | download | duplicates (12)
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
#lang web-server
(define interface-version 'stateless)
(provide start interface-version)

(define (start initial-request)
  (define counter1 0)
  (define counter2 0)
  (send/suspend/url/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)
  (let/cc k
    (letrec ([include
              (lambda (next-my-counter next-other-counter)
                `(div (h3 ,(number->string next-my-counter))
                      (a ([href 
                           ,(url->string
                             (embed/url
                              (lambda _
                                (k include
                                   (add1 next-my-counter)
                                   next-other-counter))))])
                         "Increment")))])
      (values include
              my-counter
              other-counter))))