Subject: Re: macro question...
From: (Rob Warnock)
Date: Tue, 22 Apr 2003 06:23:46 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Peter Seibel  <> wrote:
| Doug Philips <> writes:
| > What I want to have 'invokeMacro' do is both:
| >       a) return its arguments (except for the 1st one)....
| > AND   b) stash a closure of the code that is its arguments...
|     (defmacro invoke-macro (tag &body body)
|       `(progn
|         (setf (gethash ,tag *captured-code*) #'(lambda () ,@body))
|         ,@body))

If the bodies can be very large, rather than duplicating the code
one might prefer to do something like this:

	(defmacro invoke-macro (tag &body body)
	  (let ((thunk (gensym)))
	    `(flet ((,thunk () ,@body))
	       (setf (gethash ,tag *captured-code*) #',thunk)

But in any case, be aware that each time control passes through
(the expansion of) INVOKE-MACRO you're going to overwrite the
save-away code with a new version, so if you do this inside of
a loop you will only save the closure over the last iteration
of the body.


Rob Warnock, PP-ASEL-IA		<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607