[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scheme -> (X)HTML

From: Neil Jerram
Subject: Re: scheme -> (X)HTML
Date: Mon, 16 Jun 2008 22:15:28 +0100

2008/6/13 Sebastian Tennant <address@hidden>:
> Neil Jerram <address@hidden> writes:
>> As a further option, please see attached [template.scm].  If you're
>> interested in this, please let me know, because I may have a more up
>> to date version somewhere.
> I'd be interested in getting hold of the latest version of
> template.scm as it does exactly what I need for my Guile CGI scripting
> projects.

OK, I've checked now, and it appears that the code already posted is
the most up to date that I have.

> Also, how to use the process-template macro?
> Having created the file version.html which reads:
>  <html>
>   <p>This page was processed by Guile $(display (version))$</p>
>  </html>
> I can get the desired result in a REPL using primitive-eval:
> or, better still, using eval-string:
> but using the process-template macro (with a variable list and module
> requirement) produces an error:
>  guile> (process-template "/path/to/version.html" ((foo 'bar)) (ice-9 rdelim))
>  Backtrace:
>  In standard input:
>    39: 0* (process-template "/path/to/version.html" ((foo (quote bar))) ...)
>    39: 1  (let* ((module #)) (module-define! module (quote foo) ...) ...)
>  In unknown file:
>     ?: 2  [eval (begin # # # ...) #<module b7cca530>]
>     1: 3* (begin # # # ...)
>  <unnamed port>:1:1: In expression (begin (display "<html>
>  ") (display "  <p>This page was processed by Guile ") ...):
>  <unnamed port>:1:1: Unbound variable: begin
>  ABORT: (unbound-variable)

The process-template call is just slightly wrong; it just needs to
mention the (guile) module also:

   (process-template "/path/to/version.html" ((foo 'bar)) (guile)
(ice-9 rdelim))

The (guile) module contains Guile's core bindings, including `begin'.

(Possibly process-template could add (guile) automatically, but the
implementation as it stands allows for greater precision.)

> Would it not suffice to evaluate the template code in the environment
> of the CGI script, i.e., with all the modules loaded and required
> variables defined in the script before
>  (eval-string (template-code "/path/to/more-complex-template.html"))
> is called?

Interesting idea.  I didn't provide that option before, because it
wasn't helpful in the context of the program for which I wrote (ossau
template), but you can easily define another API, say `eval-template',
which does this:

(define (eval-template template . module)
  (eval (with-input-from-string (template->code template) read)
        (if (null? module) (current-module) (car module))))

Then the call would be just (eval-template

(The thing with process-template is that it allows additional variable
bindings to be set up for just that process-template call, and one
wouldn't (I think) want those bindings to persist in the whatever is
the reference module for the template code.  So process-template
currently creates a temporary module, using make-module, to avoid
this.  But this is not cast in stone; perhaps process-template should
use a surrounding `let' form instead to set up the bindings, or
perhaps it would be better for the template file to begin with

$(use-modules (ice-9 rdelim))$

instead of having (ice-9 rdelim) in the process-template call.  I'm not sure.)

> Could you perhaps provide a simple example usage of process-template?

I do have more examples, but I think this is probably already covered
above; let me know if not.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]