(defmethod methodname ((var class-name))
(pqb
`(fn ,var)))
What I'd like to do is generate it using the form
(compile
(eval
`(defmethod ,methodname ((var ,class-name))
(pqb
`(,fn ,var))))))
Of course, that doesn't work because I have two levels of backquote and two
different intended binding times of the comma-vars (the ",var" is to be
bound at method invocation time, and ",methodname" and ",fn" are to be
bound at eval time).
Any suggestions as to how I can do this? Is there a cleaner way than
constructing lists?
Thanks
Mark
____________________________________________________________
Mark Feblowitz GTE Laboratories Incorporated
mfebl...@gte.com 40 Sylvan Road, Waltham, MA 02154-1120
Does this do what you want?
(defun create-my-function (methodname class-name fn)
`(defmethod ,methodname ((var ,class-name))
(pqb
`(,',fn ,var))))
e.g. (eval (create-my-function 'mymethod 'myclass ' myfn))
Another way to think about it is to macroexpand the inner quoted form and then use only a single level of commas.
macroexpanding `(fn ,var) yields (list* 'fn (list var)).
Substituting you get
(defmethod methodname ((var class-name))
(pqb
(list* 'fn (list var))))
Now you can substitute in your three parameters using one level of commas.
(compile
(eval
`(defmethod ,methodname ((var ,class-name))
(pqb
(list* ',fn (list var))))))
If *compile-definitions* is t, which is the default then the compile is unnecessary. The eval will in fact compile the function.
Technically, you don't need to macroexpand, since backquote is a reader macro. (read-from-string "`(fn ,var)") -> (list* 'fn (list var)). But there is a keystroke (control-m) to macroexpand, and there isn't one for reading.
-Alan