unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: David Pirotte <david@altosw.be>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-user@gnu.org, "Diogo F. S. Ramos" <dfsr@riseup.net>
Subject: Re: #:getter procedure returns unexpected value in GOOPS
Date: Thu, 23 Apr 2015 19:56:11 -0300	[thread overview]
Message-ID: <20150423195611.566a3afb@capac> (raw)
In-Reply-To: <87a8zlygsj.fsf@pobox.com>

[-- Attachment #1: Type: text/plain, Size: 3826 bytes --]

Hello Andy,

Le Mon, 09 Mar 2015 22:58:20 +0100,
Andy Wingo <wingo@pobox.com> a écrit :

> Hi!
> 
> On Sat 26 Apr 2014 01:24, "Diogo F. S. Ramos" <dfsr@riseup.net> 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
> 
> I realize this is really late :)  But since this thread isn't linked to
> a bug, note that this is now fixed in stable-2.0 and master, to match
> the behavior in Guile 1.8 and previous, which is actually that:
> 
>   (foo-a (make <bar>)) => error!
> 
> because <bar> doesn't just define a different init-value for the slot,
> it defines a different slot entirely.

I'm late too :)

I am afraid this was an unfortunate and quite terrible [design? I doubt] bug in
Guile-1.8 then. Indeed, even Stklos does correctly implement subclass slot
redefinition as specified by the clos protocol [*]

;;; subclass-slot-redefinition.scm starts here
(define-class <person> ()
  ((name :accessor name :init-keyword :name :init-form "")
   (age :accessor age :init-keyword :age :init-form -1)))

(define-class <teacher> (<person>)
  ((subject :accessor subject :init-keyword :subject :init-form "")))

(define-class <maths-teacher> (<teacher>)
  ((subject :init-form "Mathematics")))
;;; ends here

david@capac:~/alto/projects/stklos 8 $ stklos
*   STklos version 1.10
 *  Copyright (C) 1999-2011 Erick Gallesio - Universite de Nice <eg@unice.fr>
* * [Linux-3.16.0-4-amd64-x86_64/pthread/readline/utf8]
stklos> (load "subclass-slot-redefinition.scm")
stklos> (define p2 (make <maths-teacher> :name 'john :age 34))
;; p2
stklos> (describe p2)
#[<maths-teacher> b34420] is an an instance of class <maths-teacher>.
Slots are: 
     age = 34
     name = john
     subject = "Mathematics"
stklos> 

[*]

In summary, the clos protocol says:

	[ this is a copy/paste from a clos tutorial, also pointed by
	[ the Stklos reference manual:

	[	http://www.aiai.ed.ac.uk/~jeff/clos-guide.html#slots

	When there are superclasses, a subclass can specify a slot that has already
	been specified for a superclass. When this happens, the information in slot
	options has to be combined. For the slot options listed above, either the
	option in the subclass overrides the one in the superclass or there is a
	union:

	   :ACCESSOR  -  union
	   :INITARG   -  union
	   :INITFORM  -  overrides

	This is what you should expect. The subclass can change the default initial
	value by overriding the :initform, and can add to the initargs and accessors.

	However, the union for :accessor is just a consequence of how generic
	functions work. If they can apply to instances of a class C, they can also
	apply to instances of subclasses of C. (Accessor functions are generic.)

Note that the last sentence, which applies to getters and setters of course, is of
prime importance wrt our previous conversation and my reported bug about setters,
which must be inherited:

	wrt setters not being inherited, the current situation not only creates
	technical problems [it forces users to a [bad imo] programming style to
	overcome the bug] but it introduced a dual semantic for define-method and
	breaks this fundamental [language designed] rule: "... If they can apply to
	instances of a class C, they can also apply to instances of subclasses of
	C..."

Cheers,
David


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

      reply	other threads:[~2015-04-23 22:56 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
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 [this message]

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=20150423195611.566a3afb@capac \
    --to=david@altosw.be \
    --cc=dfsr@riseup.net \
    --cc=guile-user@gnu.org \
    --cc=wingo@pobox.com \
    /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).