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: David Pirotte
Subject: Re: #:getter procedure returns unexpected value in GOOPS
Date: Sun, 27 Apr 2014 19:14:51 -0300

Hi Mark,

> > 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...

Are you sure about that? I don't have a CLOS implementation 'at hand', and did 
not
have the time to carefully (re)read the hyperspec doc (my knowledge of it is 
quite
rusty now, it's been a very [very] long time since I studied it), but iirc, 
where
the slot list of a subclass must be computed as being the union of ..., I am not
sure it implies that a particular slot definition should result as the union of
getters, setters, accessors and any of the previously defined slot option 
actually.
Consider the following situation:

        (use-modules (oop goops))

        (define-class <foo> ()
          (a #:accessor blue
             #:allocation #:virtual
             #:slot-ref (lambda (obj) 'foo)
             #:slot-set! (lambda (obj val) (values))))

        (define-class <bar> (<foo>)
          (a #:accessor red #:init-value 'bar))

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

        (define foo (make <foo>))
        (define bar (make <bar>))

        (blue bar)
        (red bar)
        (set! (blue bar) 'the-blue-bar)
        (set! (red bar) 'the-red-bar)
        (blue bar)
        (red bar)
        ...

> 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'.

To me it is the right answer, the slot must be (re)defined, and not inherit any
previously defined slot options, but of course I might be wrong.

Cheers,
David



reply via email to

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