[cl-who-devel] Specifying prologues (and a digression into special variables)

Ken Harris kengruven at gmail.com
Sun Oct 26 00:15:40 UTC 2008


Hi,

I'm using cl-who for a project where I want to generate 2 kinds of
XML, and each has their own prologue.  I started by passing these as
literals to the keyword parameter :prologue, but I'd like to pull them
out into constants, and eventually one will need to be computed at
runtime.

At first, I tried just passing an expression to :prologue, but that
obviously failed (because defmacro evaluates it at macroexpand-time,
not run-time, I think):

  (defconstant +my-prologue+ "header")
  (with-html-output-to-string (s nil :prologue +my-prologue+) (:a))
=>
  "
<a></a>"

Then I went and read Erann Gat's "Idiot's Guide to Special Variables".
 It doesn't mention macros, but I figured I could get close with
something like this, but no, it ignores my *prologue* setting:

  (let ((*prologue* "header"))
    (with-html-output-to-string (s nil :prologue t) (:a)))
=>
  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<a></a>"

So obviously I'm missing the boat on special variables and defmacro.
I know I could just setq *prologue* before calling cl-who (or even
cruder approaches), but that seems awkward, and I'd like to learn
what's going on with special variables and macros.

As an aside, special variables and macros aren't behaving the same in
my 2 Lisp implementations (all of the above is with SBCL), so it seems
that at least somebody out there thinks the same way as me:  :-)

  (defvar *special* 5)
  (defun show-special () *special*)
  (defmacro with-special () *special*)
  (show-special)
  (let ((*special* 10)) (show-special))
  (with-special)
  (let ((*special* 10)) (with-special))

  ;; CLISP 2.43: 5, 10, 5, 10
  ;; SBCL 1.0.13: 5, 10, 5, 5

If anybody could shed some light on this, and show how to most
naturally use an expression as a :prologue with cl-who, it'd be much
appreciated.

Thanks!


- Ken




More information about the Cl-who-devel mailing list