From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Pirotte Newsgroups: gmane.lisp.guile.user Subject: Re: #:getter procedure returns unexpected value in GOOPS Date: Thu, 23 Apr 2015 19:56:11 -0300 Message-ID: <20150423195611.566a3afb@capac> References: <87mwf9hu1v.fsf@nebulosa.milkyway> <87a8zlygsj.fsf@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; boundary="Sig_/H5dqK1JaYYcjss86zKduQvq"; protocol="application/pgp-signature" X-Trace: ger.gmane.org 1429829840 11260 80.91.229.3 (23 Apr 2015 22:57:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 23 Apr 2015 22:57:20 +0000 (UTC) Cc: guile-user@gnu.org, "Diogo F. S. Ramos" To: Andy Wingo Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Apr 24 00:57:08 2015 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YlQ3O-0007CE-RS for guile-user@m.gmane.org; Fri, 24 Apr 2015 00:57:07 +0200 Original-Received: from localhost ([::1]:42218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlQ3O-0002mf-09 for guile-user@m.gmane.org; Thu, 23 Apr 2015 18:57:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlQ3D-0002mP-Pv for guile-user@gnu.org; Thu, 23 Apr 2015 18:56:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YlQ36-0003FY-W2 for guile-user@gnu.org; Thu, 23 Apr 2015 18:56:55 -0400 Original-Received: from maximusconfessor.all2all.org ([79.99.200.102]:60034) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlQ36-00034p-O4 for guile-user@gnu.org; Thu, 23 Apr 2015 18:56:48 -0400 Original-Received: from localhost (unknown [192.168.0.2]) by maximusconfessor.all2all.org (Postfix) with ESMTP id B0A8EA04C14F; Fri, 24 Apr 2015 00:56:26 +0200 (CEST) Original-Received: from maximusconfessor.all2all.org ([192.168.0.1]) by localhost (maximusconfessor.all2all.org [192.168.0.2]) (amavisd-new, port 10024) with ESMTP id HcIQ9WFqddhV; Fri, 24 Apr 2015 00:56:14 +0200 (CEST) Original-Received: from capac (unknown [179.210.42.79]) by maximusconfessor.all2all.org (Postfix) with ESMTPSA id D214DA04C0F1; Fri, 24 Apr 2015 00:56:13 +0200 (CEST) In-Reply-To: <87a8zlygsj.fsf@pobox.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 79.99.200.102 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:11813 Archived-At: --Sig_/H5dqK1JaYYcjss86zKduQvq Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello Andy, Le Mon, 09 Mar 2015 22:58:20 +0100, Andy Wingo a =C3=A9crit : > Hi! >=20 > On Sat 26 Apr 2014 01:24, "Diogo F. S. Ramos" writes: >=20 > > 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 () > > (a #:init-form 'foo #:getter foo-a) > > (b #:init-form 42)) > > > > (define-class () > > (a #:init-form 'bar)) > > > > (foo-a (make )) =3D> foo > > (foo-a (make )) =3D> 42 > > > > I expected: > > > > (foo-a (make )) =3D> bar >=20 > 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: >=20 > (foo-a (make )) =3D> error! >=20 > because 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] bu= g 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 () ((name :accessor name :init-keyword :name :init-form "") (age :accessor age :init-keyword :age :init-form -1))) (define-class () ((subject :accessor subject :init-keyword :subject :init-form ""))) (define-class () ((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 * * [Linux-3.16.0-4-amd64-x86_64/pthread/readline/utf8] stklos> (load "subclass-slot-redefinition.scm") stklos> (define p2 (make :name 'john :age 34)) ;; p2 stklos> (describe p2) #[ b34420] is an an instance of class . Slots are:=20 age =3D 34 name =3D john subject =3D "Mathematics" stklos>=20 [*] 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 accesso= rs. 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 se= tters, 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 --Sig_/H5dqK1JaYYcjss86zKduQvq Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJVOXiLAAoJEPN0/ZOjBXrX5SAH/09GVfxmH4J4qqdvl9KcB20B OT8yJk9n7OzAcxFxzMK3D5OBDGZLAYeRHhcmJQTXPQy1Dz1qrDTi8baFjl48YnTY KfXIle4O/+/0nPm83WbTXdXuzlPeAvhzhWEu9Gnt7lSTVmzuqUe6WXNsuuTvDOz2 hfQg5qqJGiL8mGa/31qqmNfP+8nZZNiq0za3fJjpwy4V+p9osHwSUevhRSMDBwAf 9Z38aBbPi5E97ARYGDzmy9Y1S6gk67FIfstcQByhF2jGi77t7O5BjjSbDWtO8pad 0McKMiSsKsOApRH6OYzA4btWVxfubpZR38K6/uX87dE86DXYiPM+7gN1JVVjkGU= =fXbz -----END PGP SIGNATURE----- --Sig_/H5dqK1JaYYcjss86zKduQvq--