[plt-scheme] Classes, super and apply

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Thu Dec 7 12:48:15 EST 2006

On Thu, 7 Dec 2006, Dave Gurnell wrote:

> Dear All,
> Is there any way to use "apply" on the "super" and "this" forms in a class? 
> I'm thinking of something like the following:

[code cut]

Hi Dave,

Here's a revised version of the code:

(module test mzscheme
   (require (lib "class.ss")
            (lib "kw.ss"))

   (define a%
     (class object%
       (public my-method)

       (define my-method
         (lambda/kw (#:key [a #f] [b #f])
           (list a b)))))

   (define b%
     (class a%
       (override my-method)

       (define my-method
         (lambda/kw (#:key [c #f] [d #f] #:other-keys+body other)
           (append (super my-method . other) (list c d))))))

   (send (make-object b%) my-method #:a 1 #:b 2 #:c 3 #:d 4))

I added super-new calls to initialize the classes, plus fixed the call to 
super.  SUPER requires the identifier name of the thing you're super-ing.

Best of wishes!

Posted on the users mailing list.