[cl-who-devel] Macro expansion...

Edi Weitz edi at agharta.de
Fri Aug 15 22:38:26 UTC 2008


On Fri, 15 Aug 2008 17:09:35 -0400, "Andrei Stebakov" <lispercat at gmail.com> wrote:

> I am trying to incorporate parenscript into cl-who tree. I tried to
> insert a small macro but for some reasons I get various errors linke
> "cl-who:fmt not defined" or ":script not defined".  I guess I need
> help to figure out the way macros work with cl-who...
>
> (defmacro js-body (&rest body)
>   `(:script :type "text/javascript"
>             (fmt
>              (ps
>                , at body))))

This won't work and has been discussed before.  Search the CL-WHO
mailing list for previous discussion of the same topic.  Basically,
CL-WHO (like all the other HTML generators I'm aware of) transforms
its body, but it doesn't expand all macros in the body first.  You'd
need a full code walker for that.  (Google for "Lisp Code Walker".)

> (LET ((*STANDARD-OUTPUT* (MAKE-STRING-OUTPUT-STREAM :ELEMENT-TYPE
> 'CHARACTER)))
>   (UNWIND-PROTECT
>       (PROGN
>        (WITH-HTML-OUTPUT (*STANDARD-OUTPUT* NIL :PROLOGUE NIL :INDENT NIL)
>                          (:HTML (:HEAD (:TITLE "Some title"))
>                           (JS-BODY (DEFUN SOME-FUNC () (ALERT "Hello!"))))))
>     (CLOSE *STANDARD-OUTPUT*))
>   (GET-OUTPUT-STREAM-STRING *STANDARD-OUTPUT*))
>
> The HyperSpec says: "*macroexpand* <#macroexpand> repeatedly expands
> *form*until it is no longer a *macro form"*
> <26_glo_m.htm#macro_form>

Right.  (LET ...) is not a macro form.

> Why js-body or with-html-output doesn't get expanded in this case?

Again, for what you want, you will need a full code walker.  Try
something like "Walk Form" in LispWorks or slime-macroexpand-all (I
think that's how it's called) in SLIME.

Edi.



More information about the Cl-who-devel mailing list