Peter Seibel <email@example.com> wrote:
| Doug Philips <firstname.lastname@example.org> 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)
| (setf (gethash ,tag *captured-code*) #'(lambda () ,@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 <email@example.com>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607