[plt-scheme] Embedding scheme in web pages

From: Noel Welsh (noelwelsh at yahoo.com)
Date: Fri Jan 19 11:15:51 EST 2007

I don't advocate it as a good way to build web sites (I
fact, I think the opposite) but if you want to embed Scheme
in HTML you can use the preprocessor library.  Delimit your
Scheme with << >> and use the command line mzpp or
apply-template given below.

Let me know if you have any quesitons on the code.


(module preprocess mzscheme

  (require (lib "mzpp.ss" "preprocessor")
           (planet "namespace.ss" ("schematics"

  (provide apply-template)
  ;; apply-template : (U string port) (alist-of symbol any)
-> string
  (define (apply-template template bindings)
    (let ((op (open-output-string)))
        ((current-output-port op))
        (let ((ns (make-namespace 'initial)))
           '(lib "mzpp.ss" "preprocessor"))
            (lambda (cell)
              (let ((key (car cell))
                    (val (cdr cell)))
                (eval `(define ,key ,val))))
           (eval `(preprocess ,template)))))
      (get-output-string op)))

--- Maarten Koopmans <maarten at vrijheid.net> wrote:

> Hi,
> > Search for "xexpr" in the HelpDesk.
> Thanks.
> > Returning
> > 
> >   `(html (head (title "A title"))
> >          (body ,(+ 1 2)))
> > 
> > as the result of a servlet will generate the
> > wanted output.
> Yes, but say I build a website with a lot of
> Javascript/CSS and a 
> separate web designer, this is'nt what you want. Is there
> a wy to add an 
> input/output filter to the PLT webserver for some file
> extensions/mime 
> types?
> --Maarten
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Email: noelwelsh <at> yahoo <dot> com   noel <at> untyped <dot> com
AIM: noelhwelsh
Blogs: http://monospaced.blogspot.com/  http://www.untyped.com/untyping/

Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.

Posted on the users mailing list.