Re: macro for export-xml-rpc-method
Willem Broekema <[email protected]> Wed, 29 Jul 2009 13:41:09 +0200
| Newsgroups | gmane.lisp.allegro |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Jul 29, 2009 at 11:28 AM, jcb<[email protected]> wrote: > The signature of export-xml-rpc-method is: > > (export-xml-rpc-method server '("method1" method1) :int :int :int) So export-xml-rpc-method is a macro... > (defparameter *my-methods* > =A0 =A0'((("wg-base.foo" foo) :struct :string :int :string :string) > =A0 =A0 =A0(("wg-base.bar" bar) :int :struct) > =A0 =A0 =A0(("wg-base.barf" barf) :array))) > > I have fiddled unsuccessfully with the following: > > (defmacro call-export (server method-spec types-list) > =A0 `(export-xml-rpc-method ,server ',method-spec ,@types-list)) > > (defun export-my-methods (server) > =A0(mapcar #'lambda (exported-method) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0(destructuring-bind (method &rest types) exported-method > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 (call-export server method types))) *my-methods*)) Right, the arguments (server etc) to call-export are not evaluated as it is a macro. Move the construction of the macro forms to read time: (eval-when (:compile-toplevel :load-toplevel :execute) (defparameter *my-methods* ..)) #.(progn ,@(loop for (server method-spec types-list) in *my-methods* collect (export-xml-rpc-method ,server ',method-spec ,@types-list))) > Is there a way to do this or am I completely crazy for even trying...??? The read-time processor #. is the neat solution when you need to generate a bunch of similar macro forms. It's much better than something like (eval `(call-export ..)) because with #. the compiler sees the expansion and can optimize it, register the source location of the definition, etc. - Willem