This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: GOOPS: inherit method


Sascha Ziemann <szi@aibon.ping.de> writes:

> (define-method str ((obj <1D>))
>   (number->string (slot-ref obj 'x)))

[...]

> (define-method str ((obj <2D>))
>   (string-append "{"
>                  (str (change-class (shallow-clone obj) <1D>))
>                  ";"
>                  (number->string (slot-ref obj 'y))
>                  "}"))

There is currently no way of calling a method for a specified
superclass of an object (although this is possible to implement), but
you can do:

(define-method str ((obj <2D>))
  (string-append "{"
                 (next-method obj)
                 ";"
                 (number->string (slot-ref obj 'y))
                 "}"))

An alternative solution is

(define-method 1D-str ((obj <1D>))
  (number->string (slot-ref obj 'x)))

(define-method str ((obj <1D>))
  (1D-str obj))

(define-method str ((obj <2D>))
  (string-append "{"
                 (1D-str obj)
                 ";"
                 (number->string (slot-ref obj 'y))
                 "}"))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]