[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: tagged string builder
From: |
Keisuke Nishida |
Subject: |
Re: tagged string builder |
Date: |
Sat, 24 Mar 2001 16:25:45 -0500 |
User-agent: |
Wanderlust/2.4.0 (Rio) SEMI/1.13.7 (Awazu) FLIM/1.13.2 (Kasanui) Emacs/21.0.99 (i686-pc-linux-gnu) MULE/5.0 (SAKAKI) |
At Sat, 24 Mar 2001 13:49:28 -0500,
Keisuke Nishida wrote:
>
> This is a simple tagged string builder:
This is a better version:
guile> (load "tag-read.scm")
guile> (read-hash-extend #\# tag-read)
guile> (define title "Guile Home Page")
guile> (define url "http://www.gnu.org/software/guile/")
guile> (display ##(html ##(head ##(title title))
##(body ##(a #:href url title))))
<html><head><title>Guile Home Page</title>
</head>
<body><a href="http://www.gnu.org/software/guile/">Guile Home Page</a>
</body>
</html>
------------------------------------------------------------------------
(define-public (tag-read ch port)
(let* ((ls (read port))
(tag (let ((x (car ls)))
(cond ((symbol? x) (symbol->string x))
(else (error "Invlaid tag:" x))))))
(let loop ((ls (cdr ls)) (ks '()) (bs '()))
(if (null? ls)
`(string-append ,(format #f "<~A" tag)
,@(reverse! ks)
">"
,@(reverse! bs)
,(format #f "</~A>\n" tag))
(let ((x (car ls)))
(if (keyword? x)
(let ((k `(format #f " ~A=\"~A\""
',(keyword->symbol x)
,(cadr ls))))
(loop (cddr ls) (cons k ks) bs))
(loop (cdr ls) ks (cons x bs))))))))