[plt-scheme] send/suspend return values
Jordan, Matthias,
Many thanks for your responses!
To make sure I understand, is it the the unquote-splicing call
, at loptions in my code that results in the second traversal?
From Jordan's post:
> It seems that passing the data into make-form is the right way to do
> it.
Do you say this becuase it's better style - time complexity is the
same, right?
From Matthias's post:
> If your sample code is really representative and your goal is to get
> these large list of "random" things directly into a web page (which is
> different from the above), you need to perform a loop fusion manually
> (aka deforestation).
Yeah, that was the goal.
> (which is different from the above)
By "above" are you referring to my original example?
Many thanks again!
Cheers,
David
On Sun, Nov 21, 2004 at 09:25:16AM -0800, Jordan Johnson wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
> 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
> let-values
> (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)))
> (send/finish
> `(html
> (center ,(format "You selected the number ~a"
> lnum)))))))))
>
> Let me know if I'm missing something...
>
> jmj
>
> >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
> >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)))
> > (send/finish
> > `(html
> > (center ,(format "You selected the number ~a"
> >lnum)))))))))
> >
> > (doit 20))
> >
> >
> --
> Jordan Johnson (Email manipulator #22483617)