[plt-scheme] Web framework question

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Sat Apr 10 11:13:55 EDT 2010

Simple answer: Templates are compiled into your application. Thus, you
need to recompile and restart.

Long answer 1: Why are they compiled in?

Since templates can include arbitrary Scheme code and refer to
arbitrary identifiers, an 'include-template' is *really* just a funny
'require' statement.

Long answer 2: Why do you need to restart your server when you recompile?

You are using serve/servlet and passing it the closure named
'render-blog'. If the code that creates that closure changes, there's
no way to know that and update it.

Long answer 3: What if I didn't use serve/servlet?

However, even if you were using a filesystem-based servlet-dispatcher,
it still wouldn't do what you might think when you run
'conf/refresh-servlets' (which deletes the compiled code cache and
thus finds new closures the next time you go to your app); that is if
you expect it to update the template for continuations you've already
captured. That's because the captured continuations are like closures,
so they refer to the old data from the original code not the new data
from the recompiled code. It is not possible to 'port the
continuation' to change these references because the new code can be
arbitrarily different.

Long answer 4: What if I used serializable continuations?

Continuations are serialized with a hash that ensures that any source
code modifications makes all the old continuations incompatible for
the same reason native continuations naturally are.

Long answer 5: Is there any way to trick it?

Of course. If you use a model-view-controller structure with three
different modules, then when you update the template you're changing
the view module. However, the continuations will be serialized with
the controller's module code hash (because you obeyed MVC well), thus
everything still works: good job!

Long answer 6: Is there any way to trick it without serialized continuations?

Of course. Put your include-template in an "eval". So that it all
happens at runtime anyway. This will be slower (but who cares on the
Web.) [I write "eval" because eval is a pain to use and something like
sandboxes might actually be more straight-forward.]

Jay

p.s. I will put something like this in the FAQ.

On Sat, Apr 10, 2010 at 8:50 AM, Sergey <power.real at gmail.com> wrote:
> Hello everybody!
> I try to write a simple blog web-application.
> And cannot find the way to change template file without restarting application.
>
> my code is very similar to code from "Continue: Web Applications in
> PLT Scheme" http://docs.plt-scheme.org/continue/index.html
>
> (define (render-blog request)
>  (local ((define (response-generator make-url)
>            `(html ,(make-cdata #f #f (include-template "template/1.html"))))
>          (define (insert-post-handler request)
>            (begin
>              (insert-post-from-bindings (request-bindings request))
>              (render-blog request))))
>  (send/suspend/dispatch response-generator)))
>
> (serve/servlet render-blog
>               #:port 8080
>               #:listen-ip #f
>               #:command-line? #t
>               #:servlet-path "/")
>
> or http://gist.github.com/362047
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.