[plt-scheme] abstract methods/classes

From: Neil W. Van Dyke (neil at neilvandyke.org)
Date: Sat Mar 22 23:09:30 EST 2003

Matthew Flatt <mflatt at cs.utah.edu> writes at 06:45 22-Mar-2003 -0700:
> Interesting idea. What if you added something like
>  (unless (this . is-a? . <some-interface>)
>    (error "didn't implement required methods"))

That does exactly what I want, thanks.

Where I'd gotten stuck last night is that I was trying to use procedure
application syntax directly to invoke the subclass method (like m1's use
of m2 below), which is an error.  Substituting `(send this m2)' for
`(m2)' works.

    (require (lib "class.ss"))

    (define i<%> (interface () m2))

    (define c1% (class* object% ()

                  (define/public (m1) (+ 42 (m2)))  ;; ERROR: m2 is undefined

                  (super-instantiate ())

                  (unless (this . is-a? . i<%>)
                    (error "didn't implement required methods"))))

    (define c2% (class* c1% (i<%>)

                  (define/public (m2) 7)

                  (super-instantiate ())))

    (send (make-object c2%) m1)


Posted on the users mailing list.