[plt-scheme] Parameters and servlets

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Thu Feb 16 09:32:09 EST 2006

This is an example of the failure of parameters in the web server.

Your command interaction is not what the web-server does, what the
web-server does is:

(define start #f)
  (thread-wait
   (thread
    (lambda ()
      (set! start (dynamic-require "jas01.ss" 'start)))))
  (thread-wait
   (thread
    (lambda ()
      (printf "~S~n" (start 'foo)))))

Which gives the same error.

``A parameter is a setting that is both thread-specific and
continuation-specific, such as the current output port or the current
directory for resolving relative file paths.''

Thus, if a parameter is set in one thread, then another thread that is
not a child of that thread will not have the new setting.

What are you actually trying to do? Obviously this example is
contrived. I have a system called web-cells that solve the problems I
was having with what I thought I wanted parameters to do.

Jay

On 2/15/06, Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
> I think there is either a bug in my understanding of
> module servlets or the web-server, but I can't figure
> out which.
>
> Consider the small servlet below, which consists of
>
>   parameter-test-required
>     contains a parameter, which is initialized
>     when the module is required
>
>   parameter-test
>     the servlet, which shows when the other
>     module was required
>
> In theory it works. In practice I get a series of pages with
> this contents:
>
>    Servlet Parameter Test
>    1140048030
>
> At some point the servlet is removed from the cache,
> and then I expected to see a new time -- but in stead
> I get this:
>
>    The following error occured:
>    number->string: expects argument of type <number>; given #f
>
> I.e. the parameter suddenly has the original value and not
> the one given by evaluting the expression in the module top-level.
>
> In load-servlet/path in
>
> <http://ja.soegaard.net/planet/html/collects/web-server/dispatch-servlets.ss>
>
> dynamic-require is used to get hold of start. After reading
> "5.5. Dynamic Module Access" and "5.6 Re-declaring Modules" I
> had doubts whether dynamic-require worked the same way as I
> expected, so I tried this little test in the DrScheme repl:
>
>    > (define start (dynamic-require "parameter-test.scm" 'start))
>
>    > (start 'foo)
>    (html (head (title "Servlet Parameter Test")) (body (h1 "Servlet
>    Parameter Test") "1140048605"))
>
>    > (start 'foo)
>    (html (head (title "Servlet Parameter Test")) (body (h1 "Servlet
>    Parameter Test") "1140048605"))
>
>    > (define start (dynamic-require "parameter-test.scm" 'start))
>
>    > (start 'foo)
>    (html (head (title "Servlet Parameter Test")) (body (h1 "Servlet
>    Parameter Test") "1140048605"))
>
>    > (start 'foo)
>    (html (head (title "Servlet Parameter Test")) (body (h1 "Servlet
>    Parameter Test") "1140048605"))
>
> Which works just as it is supposed to do.
>
>
>
> The servlet code:
>
> (module parameter-test mzscheme
>    (require (lib "servlet.ss" "web-server")
>             "parameter-test-required.scm")
>
>    (provide interface-version timeout start)
>    (define interface-version 'v1)
>    (define timeout +inf.0)
>
>    ; start : request -> response
>    (define (start initial-request)
>      (report-errors-to-browser send/finish)
>      `(html (head (title "Servlet Parameter Test"))
>             (body (h1 "Servlet Parameter Test")
>                   ,(number->string (get-time)))))
>    )
>
>
> (module parameter-test-required mzscheme
>    (provide get-time)
>
>    (define load-time (make-parameter #f))
>
>    (define (get-time)
>      (load-time))
>
>    (load-time (current-seconds)))
>
>
>
> --
> Jens Axel Søgaard
>
>
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


--
Jay McCarthy <jay at cs.brown.edu>
http://jay.makeoutcity.com/


Posted on the users mailing list.