[plt-scheme] send/suspend return values

From: Jordan Johnson (jorjohns at cs.indiana.edu)
Date: Sun Nov 21 12:25:16 EST 2004

On Sunday, November 21, 2004, at 07:11  AM, David J. Neu wrote:
> 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.

I'm not sure I understand your question.  You're already looping 
through the data set a second time when you write , at loptions, and 
moving the generation of the data outside your form-builder procedure 
won't change that...

In fact, I'd argue it'd be better; as written, your make-form doesn't 
even care what lrandoms is.  It seems that passing the data into 
make-form is the right way to do it.

Is there any reason NOT to write it this way (given the same def'n of 
random-number-options you provided):

   (define doit
     (lambda (an)
       (let* ((rands/opts (random-number-options an))
              (lrandoms (car rands/opts))              ;; or better, use 
              (loptions (cadr rands/opts))
              (lrequest (send/suspend (make-form an loptions)))
					;; add loptions arg to make-form, and delete make-form's let-exps
              (lbindings (request-bindings lrequest)))
           (let ((lnum (extract-binding/single 'num lbindings)))
                (center ,(format "You selected the number ~a" 

Let me know if I'm missing something...


> 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!
> Cheers,
> David
> (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)
>           `(html
>             (center
>              (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 
>       ; 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)))
>             (send/finish
>              `(html
>                (center ,(format "You selected the number ~a" 
> lnum)))))))))
>   (doit 20))
Jordan Johnson (Email manipulator #22483617)

Posted on the users mailing list.