From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Neil Jerram" Newsgroups: gmane.lisp.guile.user Subject: Re: scheme -> (X)HTML Date: Mon, 16 Jun 2008 22:15:28 +0100 Message-ID: <49dd78620806161415u4be464a9g410073b55b581b51@mail.gmail.com> References: <20080325193702.6B6AE94049@webmail220.herald.ox.ac.uk> <2bc5f8210803251253p6f07911brcceaa1cc2bf949c1@mail.gmail.com> <87bq521qu6.fsf@ossau.uklinux.net> <3anht5tp.fsf@vps203.linuxvps.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1213651030 26491 80.91.229.12 (16 Jun 2008 21:17:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Jun 2008 21:17:10 +0000 (UTC) Cc: guile-user@gnu.org To: "Sebastian Tennant" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Jun 16 23:17:54 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1K8M5I-00039R-Lo for guile-user@m.gmane.org; Mon, 16 Jun 2008 23:17:53 +0200 Original-Received: from localhost ([127.0.0.1]:54666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K8M4U-00051k-8U for guile-user@m.gmane.org; Mon, 16 Jun 2008 17:17:02 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K8M34-00042J-Ga for guile-user@gnu.org; Mon, 16 Jun 2008 17:15:34 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K8M32-00040U-DI for guile-user@gnu.org; Mon, 16 Jun 2008 17:15:33 -0400 Original-Received: from [199.232.76.173] (port=60581 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K8M32-00040I-6t for guile-user@gnu.org; Mon, 16 Jun 2008 17:15:32 -0400 Original-Received: from rv-out-0708.google.com ([209.85.198.241]:30524) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K8M31-0005KT-Gq for guile-user@gnu.org; Mon, 16 Jun 2008 17:15:31 -0400 Original-Received: by rv-out-0708.google.com with SMTP id k29so5976538rvb.6 for ; Mon, 16 Jun 2008 14:15:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=+Lyq1cN56Zb/U20c62cK5GkJnF45LDGnkEeiC7A4hdI=; b=YD3Cnkh73eEu5OJGS7c1HdCAsNx7/KL/1h4NxyrIawuhagDC/qP545EKc84JSX+gxc FX1q+ai147wgpIQ3bbObVMyu8CZHJ0Z5mrlf17/5jmrd8Ek+DcavOLlaMcbwVGoGq4Bz mBCAyS1lvz/h7g7AB8zMK+yt2yq8TsxUYcK+Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=Fb8OCimCrVJpmCJFxQkoUGdpg3FJcqLHhORh7bROByE2oaXxAIXfJeZD+nPs4XH41Y qv6312aQurA1k/8/72uo5RGjnypmPBpJ62Ph2xUkp6xLu6FJwcpM+ouQ2W/N/ADuJxpT tH0vUWy4raHve56asUUcQSihOORVjlPIq2ZEo= Original-Received: by 10.114.125.2 with SMTP id x2mr7008895wac.59.1213650928976; Mon, 16 Jun 2008 14:15:28 -0700 (PDT) Original-Received: by 10.114.197.8 with HTTP; Mon, 16 Jun 2008 14:15:28 -0700 (PDT) In-Reply-To: <3anht5tp.fsf@vps203.linuxvps.org> Content-Disposition: inline X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6611 Archived-At: 2008/6/13 Sebastian Tennant : > Neil Jerram 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: > > >

This page was processed by Guile $(display (version))$

> > > 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 # # # ...) #] > 1: 3* (begin # # # ...) > > :1:1: In expression (begin (display " > ") (display "

This page was processed by Guile ") ...): > :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 "/path/to/more-complex-template.html"). (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. Regards, Neil