[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:29:06 EDT 2010


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%)



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.