On Mon, Oct 20, 2008 at 04:21:31PM +0100, Tomas Hlavaty wrote:
That's nice. It could even be:
(de <xml> Prg
(prin "<" (pop 'Prg))
(while (atom (car Prg))
(prin " " (pop 'Prg) "=\"" (eval (pop 'Prg) 1) "\"") )
(prin ">")
(run Prg) # the text, or other elements
(prinl "</text>") )
(<xml> text id 123 dx (+ 3 4) dy (* 3 4)
(prin "No font and color arguments yet") )
Yes, that's even better.
In addition, to make it more robust, we should
1. Check for an empty body (avoid an infinite loop):
(while (and Prg (atom (car Prg)))
2. Run the body in the binding environment of the caller:
(run Prg 1)
Cheers,
- Alex
Thanks Alex and Tomas! I really liked your ideas. Here's my current version:
(de <xml> Lst
(let Tag (pop 'Lst)
(prin "<" Tag)
(while (and Lst (atom (car Lst)))
(prin " " (pop 'Lst) "=\"" (eval (pop 'Lst) 1) "\"") )
(if (car Lst)
(prog
(prin ">")
(run Lst 1)
(prinl "</" Tag ">") )
(prinl " />") ) ) )
And it works like this:
: (<xml> hoy id 123 (<xml> inner fun "abc"))
<hoy id="123"><inner fun="abc" />
</hoy>
-> ">"
The test "(if (car Lst) ..." determines whether the current element
is a container ("hoy") or not ("inner").
Since this is "pure" XML, it would seem natural to find a function
like this <xml> in lib/xml.l. I haven't studied the functions in that
file yet, but there's one called "xml" that is said to
"Generate/Parse XML data". It could be interesting to know what that
one does that's different from the new <xml>.
/Jon
--
UNSUBSCRIBE: mailto:[EMAIL PROTECTED]