Discussion:
Macro expansion...
Andrei Stebakov
2008-08-15 21:09:35 UTC
Permalink
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
,@body))))

(with-html-output-to-string (*standard-output* nil :prologue nil :indent
nil)
(:html
(:head (:title "Some title"))
(js-body
(defun some-func ()
(alert "Hello!")))))

I think parenscript is not really relevant to the task, so I am looking for
some help to figure out why I have these expansion errors.
BTW, when I run
(macroexpand
'(with-html-output-to-string (*standard-output* nil :prologue nil :indent
nil)
(:html
(:head (:title "Some title"))
(js-body
(defun some-func ()
(alert "Hello!"))))))

I get:

(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>
Why js-body or with-html-output doesn't get expanded in this case? I am
using sbcl 1.0.18 on Ubuntu.

Thank you!
Andrew
Edi Weitz
2008-08-15 22:38:26 UTC
Permalink
Post by Andrei Stebakov
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
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".)
Post by Andrei Stebakov
(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.
Post by Andrei Stebakov
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.

Loading...