[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to write macro within macro

I would like to write a macro that takes as input the name of a flavor to be defined,
as well as the names of the instance variables, and defflavors the flavor, and then
creates a function whose name is the same as the flavor, and sets a variable to
an instance of the flavor with all fields initialized by keywords.


(def-thing foo a b c)
(defflavor foo (a b c)() :initable-instance-variables (:contructor MAKE-FOO))
(defmacro foo (id x y z) `(setq ,id (MAKE-FOO :a ,x :b ,y :c ,z)))

which then allows me to have expressions like
(foo a 1 2 (1 2)))
which after evaluation leaves me with "a" as an instance of a flavor foo,
with instance-vars a=1, b=1,c=(1 2).

Hope that makes it clear.
I can get the defflavor part from a macro, I can't figure out how to
put a defmacro into a defmacro, (how to get the backquote inside to show up,
that sort of thing.)

Any help appreciated.

David Strip