[plt-scheme] macros that need to eval

From: Robert Bruce Findler (robby at cs.uchicago.edu)
Date: Tue Jan 28 10:22:13 EST 2003

I don't think that you need to evaluate arguments for that. Have a look
at the way define-struct's super types work. (This may be described in
more detail in his ICFP paper or at http://www.htus.org/). You can use
macro-generating macros to transmit information at compile time.
Perhaps that is what you want (or would be happy with...)?

Robby

At Tue, 28 Jan 2003 10:11:34 -0500 (EST), Doug Orleans wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> 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.