unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#20423: goops - inheritance of slot options
@ 2015-04-25  2:05 David Pirotte
  2016-06-23 20:23 ` Andy Wingo
  0 siblings, 1 reply; 7+ messages in thread
From: David Pirotte @ 2015-04-25  2:05 UTC (permalink / raw)
  To: 20423

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

Hello,

	GNU Guile 2.0.11.114-649ec
	goops - inheritance of slot options
	severity - serious

The current goops implementation breaks the [clos] protocol [*] for inheritance of
slot options.  This is a serious bug.

Below, [A] what stklos does, [B] what goops does, [*] a summary of what the clos
protocol says wrt  inheritance of slot options.

Cheers,
David


[A]	Here is what stklos does:

	stklos/subclass-slot-redefinition.scm

--8<---------------cut here---------------start------------->8---
(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")))
--8<---------------cut here---------------end-------------->8---

david@capac:~/alto/projects/stklos 15 $ 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> 28a2420] is an an instance of class <maths-teacher>.
Slots are: 
     age = 34
     name = john
     subject = "Mathematics"
stklos> (subject p2)
"Mathematics"
stklos> 


[B]	Here is what goops does:

	goops/subclass-slot-redefinition.scm

--8<---------------cut here---------------start------------->8---
(use-modules (oop goops))

(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"))
--8<---------------cut here---------------end-------------->8---

david@capac:~/alto/projects/guile-tests/goops 51 $ guile
GNU Guile 2.0.11.114-649ec
Copyright (C) 1995-2014 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (load "subclass-slot-redefinition.scm")
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /usr/alto/projects/guile-tests/goops/subclass-slot-redefinition.scm
;;;
compiled /home/david/.cache/guile/ccache/2.0-LE-8-2.0/usr/alto/projects/guile-tests/goops/subclass-slot-redefinition.scm.go
scheme@(guile-user)> (define p2 (make <maths-teacher> #:name 'john #:age 34))
scheme@(guile-user)> ,use (oop goops describe) scheme@(guile-user)> (describe p2)
#<<maths-teacher> 1432300> is an instance of class <maths-teacher>
Slots are: 
     name = john
     age = 34
     subject = "Mathematics"
scheme@(guile-user)> (subject p2)
ERROR: In procedure scm-error:
ERROR: No applicable method for #<<accessor> subject (1)> in call (subject
#<<maths-teacher> 1432300>)

Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> 


[*] A summary of what 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.)

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-07-12 20:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-25  2:05 bug#20423: goops - inheritance of slot options David Pirotte
2016-06-23 20:23 ` Andy Wingo
2016-06-23 23:08   ` David Pirotte
2016-06-24  1:06     ` dsmich
2016-06-24  5:04     ` Andy Wingo
2016-07-12 20:02       ` David Pirotte
2016-06-24  5:12     ` Andy Wingo

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