[cl-who-devel] Macroexpansion of with-html-output body?

Eli Naeher enaeher at gmail.com
Sun Feb 3 04:38:18 UTC 2008


On Feb 2, 2008 4:15 PM, Jeff Cunningham <jeffrey at cunningham.net> wrote:

> I'm not sure I follow what you are suggesting. Could you give a simple
> example?

Sure -- my explanation was not a model of clarity. Here's what I've
been playing with:

(cl-who:with-html-output (var test-file :prologue t :indent t)
      (with-numbered-figures ("Fig. ~@R")
        (:h2 "Here are some images.")
        (:p "It is interesting to examine foo and bar over the past"
(:em "n") "years:")
        (png-inline ("Foo vs. Bar Over Time" stream)
          (adw-charting:with-line-chart (400 100)
            (adw-charting:add-series "Foo" '((1 1) (2 1) (3 5) (4 8)))
            (adw-charting:add-series "Bar" '((1 -3) (4 -2) (6 -1) (8 7)))
            (adw-charting:save-stream stream)))
        (:p "Here is a picture of my cat:")
        (:img :src "picture-of-my-cat.jpg" :alt "My Cat.")))

png-inline is a macro that lets its body write binary PNG data to
stream and expands to:

(:img :src "<long RFC 2397 data: URI with base64-encoded PNG>"
      :alt "Foo vs. Bar Over Time")

with-numbered-figures finds all the lists like (:img ...) in its body
and inserts:

(:div :class "caption" "Figure n")

after each one, where "Figure n" is an iterator formatted with the
specified format string.

The functionality of either of these on their own could be achieved
simply by writing macros which themselves use with-html-output and
expand to strings. However, in order for with-numbered-figures to
correctly find the (:img ...) created by the expansion of png-inline,
it is necessary that the latter expand to w-h-o forms, and, if we want
to be able to also use png-inline in w-h-o directly without using
with-numbered-figures, it is necessary that w-h-o perform
macroexpansion during its tree-walking, or else png-inline will be
expanded subsequent to the w-h-o expansion and Lisp will see it as an
attempt to call an :img function.

I hope this is a little clearer (and that GMail does not break the
formatting too badly).

Thanks,

--Eli



More information about the Cl-who-devel mailing list