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

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Sep 15 09:59:31 EDT 2010

Where do you want to bind them? In the current namespace? Scope? 


On Sep 15, 2010, at 9:47 AM, Laurent wrote:

> 
> 
> On Wed, Sep 15, 2010 at 15:29, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
> 
> 
> Would this help you:
> 
> #lang racket
> 
> (define a%
>  (class object%
>    (init-field this.x)
>    (define/public (foo x)
>      (set! this.x x))
>    (define/public (bar)
>      this.x)
>    (super-new)))
> 
> (new a% [this.x 10])
> 
> (define (generic-methods class%)
>  (map (lambda (name) (list name (make-generic class% name)))
>       (interface->method-names (class->interface class%))))
> 
> (generic-methods a%)
> 
> If I could pass the latter result to a macro that binds the names with the function automatically, yes,
> but this seems to be exactly my initial problem, I think.
> 
> 
> 
> 
> 
> On Sep 15, 2010, at 9:10 AM, Laurent wrote:
> 
> >
> >
> > On Wed, Sep 15, 2010 at 14:57, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
> >
> > 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?
> >
> > Okay, let me explain what I want to do (the name is not really set in stone yet).
> >
> > There is a class a% defined somewhere, and an instance parameter
> > current-a%-object of class a%.
> > Suppose a% has methods foo and bar.
> >
> > Then I call:
> > (class->singleton a% current-a%-object)
> >
> > This is supposed to define the forms (foo ....) and (bar ....) so that they act like
> > (send (current-a%-object) foo ....), etc.
> >
> > I want to build these definitions automatically from the methods of the class.
> >
> > Anyway, beside the intended goal, I'd still like to know how solve the macro issue.
> >
> 
> 



Posted on the users mailing list.