[racket] Help: Passing a class to a macro and not an identifier

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Wed Sep 15 09:19:24 EDT 2010

The class exists at runtime, not at compile time, so you can't just
take an identifier like that and get the names of the methods back.
(This is a fundamental difference between our class system and ones
like in Java. See
http://www.eecs.northwestern.edu/~robby/pubs/papers/aplas2006-fff.pdf
for more info about the high level properties of the class system.)

At least not with the current class system. You can, however, define a
macro, something like:

(define-class <name> <class-expr>)

and then have define-class inspect the class-expr to find the method
names (note you'll have to use local-expand to make this work) and put
that information into <name> at compile time.

hth,
Robby

On Wed, Sep 15, 2010 at 7:50 AM, Laurent <laurent.orseau at gmail.com> wrote:
> Dear all,
>
> Apparently I still don't have my macro writing licence.
> I'm stuck somewhere around syntax-case and with-syntax.
>
> Here is my problem.
> Suppose something like this:
>
> (define-syntax (class->singleton stx)
>   (syntax-case stx ()
>     [(_ cl)
>      (with-syntax ([(name ...)
>                     (interface->method-names (class->interface #'cl))]) ;
> ***
>        #'(begin (define-something name)
>                 ...))]))
>
> (class->singleton a%)
>
> On line *** I want to match (name ...) with the list of method-names of
> the given class (here a%).
> Obviously, this is wrong, since #'cl is just a syntaxed identifier IIUC,
> but should be the class itself.
> datum->syntax and syntax->datum don't help either, so what should I do?
> Any hint (even an RTFM link) would be appreciated.
>
> Thanks,
> Laurent
>
>
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users
>


Posted on the users mailing list.