;; (define (count-delay)
;;   (let ([new-delay (prompt-read-num "Delay: ")])
;;     (cond [(= 0 new-delay) 0]
;;   	     [else (+ new-delay (count-delay))])))

;; (define (prompt-read-num/web prompt action)
;;   (begin
;;     (printf prompt)
;;     (action (read))))
 
;; (define (count-delay/web action)
;;   (prompt-read/web
;;    "Delay: "
;;    (lambda (box)
;;      (let ([new-delay box])
;;        (cond [(= 0 new-delay) (action 0)]
;; 	     [else
;; 	      (count-delay/web
;; 	       (lambda (box)
;; 		 (action (+ new-delay box))))])))))

(require (lib "unitsig.ss")
         (lib "servlet-sig.ss" "web-server")
         (lib "servlet-helpers.ss" "web-server")
         (lib "date.ss"))

(unit/sig () (import servlet^)

  ; prompt-read-num : -> num
  (define (prompt-read-num prompt)
    (string->number
     (extract-binding/single
      'number
      (request-bindings
       (send/suspend
	(lambda (action)
	  (generate-html-output
	   "Delay entry"
	   (list (format "<form action=\"~a\" method=post>~n" action)
		 prompt
		 "<input type=text name=\"number\" value=\"\">"
		 "<input type=submit name=\"enter\" value=\"Enter\">"))))))))

  (define (count-delay)
    (let ([new-delay (prompt-read-num "Delay: ")])
      (cond [(= 0 new-delay) 0]
	    [else (+ new-delay (count-delay))])))
  
  (send/suspend
   (lambda (action)
     (generate-html-output
      "Delay Output Page"
      (list "<p>Total wait: "
	    (number->string (count-delay))
	    "</p>")))))
