unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: David Pirotte <david@altosw.be>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-user@gnu.org
Subject: Re: #:getter procedure returns unexpected value in GOOPS
Date: Sun, 27 Apr 2014 19:14:51 -0300	[thread overview]
Message-ID: <20140427191451.674c60b2@capac> (raw)
In-Reply-To: <87ppk38tek.fsf@yeeloong.lan>

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	other threads:[~2014-04-27 22:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-25 23:24 #:getter procedure returns unexpected value in GOOPS Diogo F. S. Ramos
2014-04-26 12:26 ` Neil Jerram
2014-04-26 17:35   ` Diogo F. S. Ramos
2014-04-26 22:19     ` David Pirotte
2014-04-26 22:58       ` Diogo F. S. Ramos
2014-04-27 22:14         ` David Pirotte
2014-04-27  1:15 ` Mark H Weaver
2014-04-27 22:14   ` David Pirotte [this message]
2014-04-28  1:12     ` Mark H Weaver
2014-05-02  4:36       ` David Pirotte
2015-03-09 21:58 ` Andy Wingo
2015-04-23 22:56   ` David Pirotte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140427191451.674c60b2@capac \
    --to=david@altosw.be \
    --cc=guile-user@gnu.org \
    --cc=mhw@netris.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).