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

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Sep 15 08:57:36 EDT 2010

Can we start from something simpler? 

The name of your macro suggests that you want something like this: 

(define one-and-only-one-instance 
  (new (class my-super% ...)))

This creates a class and creates a single instance. Because class is nested
in the call to new, there is no way to get another instance. 

Would this be what you want? 

-- Matthias





On Sep 15, 2010, at 8:50 AM, Laurent 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.