This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
GOOPS: inherit method
- To: guile at sourceware dot cygnus dot com
- Subject: GOOPS: inherit method
- From: Sascha Ziemann <szi at aibon dot ping dot de>
- Date: 13 Mar 2000 12:15:09 +0100
Hi,
How can I inherit a method? It works with change-class on a clone of
the original object, but I would prefer a way to call the method
without allocating space for a copy of the object.
Example:
------------------------------------------------------------
(use-modules (oop goops))
(define-class <1D> () (x))
(define-class <2D> (<1D>) (y))
(define punkt (make <2D>))
punkt => #<<2D> 40218528>
(slot-set! punkt 'x 3.14)
(slot-set! punkt 'y 2.71)
(define-method str ((obj <1D>))
(number->string (slot-ref obj 'x)))
(str punkt) => "3.14"
(define-method str ((obj <2D>))
(string-append "{"
(str (change-class (shallow-clone obj) <1D>))
";"
(number->string (slot-ref obj 'y))
"}"))
(str punkt) => "{3.14;2.71}"
punkt => #<<2D> 40218528>
------------------------------------------------------------
Sascha
--
Freie Software ist der Ausgang des Menschen aus seiner
selbstverschuldeten Unmündigkeit. (Immanuel Kant, 1784)
http://www.fordham.edu/halsall/mod/kant-whatis.html