"Diogo F. S. Ramos" <[email protected]> writes:

> When using GOOPS, if a class has a second slot, the #:getter procedure
> of the first slot returns the value of the second slot when applied to
> an instance of a subclass.
>
> (use-modules (oop goops))
>
> (define-class <foo> ()
>   (a #:init-form 'foo #:getter foo-a)
>   (b #:init-form 42))
>
> (define-class <bar> (<foo>)
>   (a #:init-form 'bar))
>
>   (foo-a (make <foo>)) => foo
>   (foo-a (make <bar>)) => 42
>
> I expected:
>
>   (foo-a (make <bar>)) => bar

Indeed, CLOS behaves as you expected, and GOOPS should probably behave
the same way.  However, it appears that overriding the attributes of
slots in subclasses has not worked this way in a long time, if ever.

I tried this example on both Guile 1.8 and Guile 1.6, and neither of
them behave as you expected.  Instead they complain that there's no
applicable method for 'foo-a'.

Can you please send a bug report to [email protected]?

For now, I suggest adding an initialize method for <bar>, like this:

--8<---------------cut here---------------start------------->8---
(use-modules (oop goops))

(define-class <foo> ()
  (a #:init-form 'foo #:getter foo-a)
  (b #:init-form 42))

(define-class <bar> (<foo>))

(define-method (initialize (obj <bar>) args)
  (slot-set! obj 'a 'bar)
  (next-method))

(foo-a (make <foo>)) => foo
(foo-a (make <bar>)) => bar
--8<---------------cut here---------------end--------------->8---

     Regards,
       Mark

Reply via email to