Re: macro that writes macros
- From: Dan Bensen <randomgeek@xxxxxxxxxxxxxx>
- Date: Sat, 29 Dec 2007 21:06:38 -0600
jordi.burguet.castell@xxxxxxxxx wrote:
> (defmacro new-tags (&rest tags)
> (dolist (tag tags)
> `(new-tag ,tag)))
You're not doing anything with the new-tag forms. You're
not even evaluating them, because they're quoted. You're
just evaluating each backquote form, which returns an
unevaluated new-tag form, which is immediately thrown away.
Look up dolist in the hyperspec. It returns nil by default,
so your macro isn't returning anything.
What you need to do is return the whole list of new-tag
forms to be evaluated. Per Kenny the Great's answer to this
question, which I asked a few months ago, you need to wrap
the forms in a progn form so you can return all of them as
one form:
(defmacro new-tags (&rest tags)
`(progn
,@(mapcar (lambda (tag) `(new-tag ,tag))
tags)))
* (new-tags foo bar)
* (foo (bar "stuff"))
<foo>
<bar>
</bar>
</foo>
Notice that regular text doesn't get printed. If you
want to use a modern functional approach instead of cgi,
you might consider having your tag functions return a
string instead of printing it. Then you can concatenate
each pair of start/end tags with the output of the enclosed
tags, and regular text will be included. All you have to
do is output the final page once you've created it.
--
Dan
www.prairienet.org/~dsb/
.
- References:
- macro that writes macros
- From: jordi . burguet . castell
- macro that writes macros
- Prev by Date: Re: macro that writes macros
- Next by Date: Re: RFC: Extending method specializers
- Previous by thread: Re: macro that writes macros
- Next by thread: Re: macro that writes macros
- Index(es):
Relevant Pages
|