guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: #:getter procedure returns unexpected value in GOOPS


From: Mark H Weaver
Subject: Re: #:getter procedure returns unexpected value in GOOPS
Date: Sat, 26 Apr 2014 21:15:15 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

"Diogo F. S. Ramos" <address@hidden> 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 address@hidden

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

[Prev in Thread] Current Thread [Next in Thread]