[plt-scheme] Accessing class in method?

From: Sam Phillips (samdphillips at gmail.com)
Date: Tue Oct 7 19:06:08 EDT 2008

Ok, I'm not sure how clearly I can word this... I'm trying to write a
method that creates an instance of the class that it is a method on, and
I'm not sure how to go about it.  Here's an example:

> (define a%
    (class object%
      (super-new)
      (define/public (make)
        (make-object a%))))
> (make-object a%)
#(struct:object:a% ...)
> (send (make-object a%) make)
#(struct:object:a% ...)

So far so good.

> (define b%
    (class a% (super-new)))
> (make-object b%)
#(struct:object:b% ...)
> (send (make-object b%) make)
#(struct:object:a% ...)

What I want is a way for calling "make" on b% to return an instance of
b% not of a%.

Cheers,
Sam


Posted on the users mailing list.