Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Complicated quoting problem

1 view
Skip to first unread message

Mark Feblowitz

unread,
Aug 13, 1998, 3:00:00 AM8/13/98
to
I have a form that I use often. I'll simplify it to

(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


Alan Ruttenberg

unread,
Aug 13, 1998, 3:00:00 AM8/13/98
to
If I understand correctly, you want to supply methodname, classname and fn and create a function using them.

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

0 new messages