Search code examples
macroscommon-lispcl-who

cl-who: using a variable in with-html-output-to-string


All the examples I've seen so far for cl-who work like this:

(with-html-output-to-string (s)
   (:HTML (:HEAD (:TITLE "hello")) (:BODY (:DIV "world"))))

Which works fine. However, I wanted to use with-html-output-to-string with a variable, instead of a hardcoded html tree; if *p* has (:HTML (:HEAD (:TITLE "hello")) (:BODY (:DIV "world"))) and I do this

(with-html-output-to-string (s)
   *p*)

I get "" as a result. I guess that as with-html-output-to-string is a macro, it's last argument is never evaluated. Is there any way I can get around this?


Solution

  • Use cl-who:str; check the examples at http://weitz.de/cl-who/#example.

    If you do:

    (with-html-output-to-string (s)
       (str *p*))
    

    you'll get the expected output.