unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* GOOPS constructors
@ 2014-07-22 12:18 Marko Rauhamaa
  2014-07-22 12:22 ` Tobias Brandt
  0 siblings, 1 reply; 8+ messages in thread
From: Marko Rauhamaa @ 2014-07-22 12:18 UTC (permalink / raw)
  To: guile-user


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



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-07-25 10:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-22 12:18 GOOPS constructors Marko Rauhamaa
2014-07-22 12:22 ` Tobias Brandt
2014-07-22 13:03   ` Marko Rauhamaa
2014-07-22 13:09     ` Tobias Brandt
2014-07-22 13:15       ` Marko Rauhamaa
2014-07-23 15:02     ` Barry Fishman
2014-07-23 17:42       ` Marko Rauhamaa
     [not found]         ` <m3lhri21kk.fsf@barry_fishman.acm.org>
2014-07-25 10:26           ` Marko Rauhamaa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).