that's a somewhat advanced and obscure feature.
LispWorks has a built-in feature for that, which in Lisp is usually called advising.
This usually adds code to a function.
LispWorks DEFADVICE can also add code to macros: before, after and around.
It might work for your purpose...
Note that LispWorks' DEFADVICE is an extension to Common Lisp.
(defparameter *dynamic-var-0* 'foo-0)
(defmacro with-dynamic-var ((value) &body body)
`(let ((*dynamic-var-0* ,value))
,@body))
Advising a macro:
Now we want to add another level of LET binding for a different variable around it:
(defparameter *dynamic-var-1* 'foo-1)
(defadvice (with-dynamic-var around-with-dynamic-var :around)
(call-form env)
(destructuring-bind (with-dynamic-var-symbol (value) &body body)
call-form
(declare (ignore with-dynamic-var-symbol body))
`(let ((*dynamic-var-1* (1+ ,value)))
,(call-next-advice call-form env))))
The lambda list is call-form and env, which means we need to destructure it.
CALL-NEXT-ADVICE then calls the next macro implementation.
Example use:
(defun test (bar)
(with-dynamic-var (bar)
(list :var-0 *dynamic-var-0*
:var-1 *dynamic-var-1*)))
Regards,
Rainer
Hi,
I’m curious: is there a way to ”extend” an imported macro?
Let’s say I have a package defining a macro:
(in-package :silly-macros)
(defmacro with-dynamic-var ((value) &body body)
`(let ((*dynamic-var* ,value))
,@body))
Now, in the code that uses silly-macros, I would like to use with-dynamic-var, but I would also like to do something more (like binding another dynamic variable).
Obviously I could define a new macro and call with-dynamic-var in its definition, but what I really would like to do is to have a new macro with extended behavior *using the same name*, overriding or shadowing the old.
Is this possible?
Erik
_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.comhttp://www.lispworks.com/support/lisp-hug.html