[plt-scheme] macros that need to eval

From: Doug Orleans (dougo at ccs.neu.edu)
Date: Tue Jan 28 10:11:34 EST 2003

Eli Barzilay writes:
 > Would you want this:
 >   (let ((x 4))
 >     (arity-thunk x (newline)))
 > to expand to the same thing?  How about this:
 >   (arity-thunk (read) (display x4))

Yes, I meant for the first argument to be an expression that evaluates 
to an integer.  The second argument should not be able to access the
generated parameters, though, so (display x4) wouldn't work (unless x4 
were already accessible in the context of the macro call).

What I'm really doing is playing around with a class system where

    (define-class foo% (bar%) (x y z))

defines a subclass of bar% with fields x, y, and z.  However, unlike
define-struct, the parent list is a list of values, rather than
structure type descriptors (which are syntactic elements).  The
problem is that in order to generate the constructor, I need to know
how many fields are in the parents, so I need to inspect the run-time
value of the parent classes in order to determine the arity of the
constructor.  I think I can get away with using rest arguments, but it 
made me curious whether there was some trick to writing a macro that
evaluated some of its arguments.  I think the only way to do it is
with eval, which isn't so bad as long as it's okay to generate the
procedure in the top-level environment.

--dougo at ccs.neu.edu

Posted on the users mailing list.