[plt-scheme] send/suspend return values

From: David J. Neu (djneu at att.net)
Date: Sun Nov 21 10:11:20 EST 2004

Hi all, 

I have a servlet that generates a list of data, and as the data is
generated, it is put into an HTML table.

I'm wondering if it's possible to have the procedure that is the
argument to a send/suspend call (i.e. the procedure MAKE-FORM in the
example below), return multiple values, e.g. the HTML and the list of

My alternative is to generate the list of data and then pass it into
the procedure MAKE-FORM, however, I'd like to avoid looping through
the data set twice.

The real application is a web-based database application, but I
thought this self-contained example made the point more succinctly.

Many thanks for any help!


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

(unit/sig () (import servlet^)

  (define random-number-options
    (lambda (an)
      (let loop ((ln an)
                 (lrandoms '())
                 (loptions '()))
        (if (zero? ln)
            (list lrandoms loptions)
            (let ((lrandom (random an)))
              (loop (sub1 ln)
                    (cons lrandom lrandoms)
                    (cons (list 'option (format "~a" lrandom)) loptions)))))))                    
  (define make-form
    (lambda (an)
      (let ((llist (random-number-options an)))
        (let ((lrandoms (car llist))
              (loptions (cadr llist)))
        (lambda (k-url)
             (form ((action ,k-url) (method "post"))
                   (p "Please select a number: ")
                   (p (select ((name "num")) , at loptions))
                   (p (input ((type "submit") (value "OK"))))))))))))

  (define doit
    (lambda (an)
      ; I'd like to have the list of random numbers i.e. the variable lRANDOMS
      ; in procedure MAKE-FORM available here, i.e. have it returned in
      ; addition to lrequest
      (let ((lrequest (send/suspend (make-form an)))) 
        (let ((lbindings (request-bindings lrequest)))
          (let ((lnum (extract-binding/single 'num lbindings)))
               (center ,(format "You selected the number ~a" lnum)))))))))
  (doit 20))

Posted on the users mailing list.