Consider this simple program:

========================================================================
(use-modules
 (oop goops)
 (ice-9 optargs))

(define-class <rectangle> ()
  (width #:accessor width #:init-keyword #:width)
  (height #:accessor height #:init-keyword #:height))

(define-method (area (@ <rectangle>))
  (* (height @) (width @)))

(define-class <square> (<rectangle>)
  (side #:accessor side #:init-keyword #:side))

(define-method (initialize (@ <square>) args)
  (let-keywords
   args #f ((side #f))
   (next-method @ (list #:width side #:height side))))

(format #t "~S\n" (area (make <square> #:side 3)))
(format #t "~S\n" (side (make <square> #:side 3)))
========================================================================

The program outputs:

========================================================================
9
ERROR: Unbound slot in object #<<square> b76cfec0>
========================================================================

I understand that by overriding <square>'s initialize method I'm losing
the magic of the default initializer. How could I have the cake and eat
it, too?


Marko

Reply via email to