<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I've been trying to write a macro which will take
an interface and create a class which forwards all calls to the interface's
methods on to another implementation of that interface. For example, given
this interface:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>(define ifoo<%> (interface () foo bar
baz))</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I want my macro</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>(wrap ifoo<%>)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>to expand to this:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>(class* object% (ifoo<%>)</FONT></DIV>
<DIV><FONT face=Courier size=2> (init-field (impl
void))</FONT></DIV>
<DIV><FONT face=Courier size=2> (public*</FONT></DIV>
<DIV><FONT face=Courier size=2> (foo (lambda args
(send impl foo . args)))</FONT></DIV>
<DIV><FONT face=Courier size=2> (bar (lambda args
(send impl bar . args)))</FONT></DIV>
<DIV><FONT face=Courier size=2> (baz (lambda args
(send impl baz . args)))</FONT></DIV>
<DIV><FONT face=Courier size=2> (set-impl (lambda
(i) (set! impl i))))</FONT></DIV>
<DIV><FONT face=Courier size=2> (super-instantiate ())</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>The first three methods of this class simply
forward requests to the ifoo<%> interface onto impl. The set-impl
method allows me to change the implementation under the covers without any of
the clients of my object knowing or having to update their references to the new
impl.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Now, what I have started with is this:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>(define-syntax (wrap stx)</FONT></DIV>
<DIV><FONT face=Courier size=2> (syntax-case stx ()</FONT></DIV>
<DIV><FONT face=Courier size=2> ((wrap
iface<%> (method ...))</FONT></DIV>
<DIV><FONT face=Courier size=2>
#`(class* object% (iface<%>)</FONT></DIV>
<DIV><FONT face=Courier
size=2> (init-field
(impl void))</FONT></DIV>
<DIV><FONT face=Courier
size=2> (public*</FONT></DIV>
<DIV><FONT face=Courier
size=2> (set-impl
(lambda (i) (set! impl i)))</FONT></DIV>
<DIV><FONT face=Courier
size=2> (method
(lambda args (send impl method . args))) ...)</FONT></DIV>
<DIV><FONT face=Courier
size=2> (super-instantiate
())))))</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Which works great (ie it produces the correct
class) except that I have to invoke the macro like this:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>(wrap ifoo<%> (foo bar baz))</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I don't want to have to list all the method names
out everytime I use this wrapper. What if I change the method names in the
interface? Now I have to go back and change all the invocations of the
macro as well. Lousy. So I wanted to use the
interface->method-names function to generate the list of methods and then
pass those into the macro automatically. For reference,
interface->method-names works like this:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>(interface->method-names
ifoo<%>) ==> '(foo bar baz)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>So it seems like I ought to be able to do
this:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>(wrap ifoo<%> (interface->method-names
ifoo<%>))</FONT></DIV><FONT face=Arial size=2>
<DIV><BR>However, this yeilds a class with methods "interface->method-names"
and "ifoo<%>" instead of "foo" "bar" and "baz". Or rather, doesn't
produce anything since that class doesn't properly implement ifoo<%></DIV>
<DIV> </DIV>
<DIV>What I've come up with is this hack:</DIV>
<DIV> </DIV>
<DIV><FONT face=Courier>(define make-wrapper</FONT></DIV>
<DIV><FONT face=Courier> (lambda (iface<%>)</FONT></DIV>
<DIV><FONT face=Courier> (eval ` (wrap
iface<%> ,(interface->method-names iface<%>)))))</FONT></DIV>
<DIV><FONT face=Courier></FONT> </DIV>
<DIV><FONT face=Courier>(define foo-wrapper% (make-wrapper
ifoo<%>))</FONT></DIV>
<DIV><BR>But my skin crawls whenever I use eval. I've tried this out in
local and global contexts and it seems to work, but is it really kosher and is
there a cleaner way to accomplish what I want? Is there a way to combine
the make-wrapper function into the macro definition?</DIV>
<DIV> </DIV>
<DIV>Any help is appreciated.</DIV>
<DIV> </DIV>
<DIV>Dave</FONT></DIV></BODY></HTML>