bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#20423: goops - inheritance of slot options


From: Andy Wingo
Subject: bug#20423: goops - inheritance of slot options
Date: Thu, 23 Jun 2016 22:23:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Hi,

For what it's worth this is a part of GOOPS's design AFAIU: all slot
definitions are unique.  Two slots named S declared on classes A and B
are distinct, even if A is a superclass of B.

I don't know if we can change this.  I guess maybe.  There would have to
be a design though.  I guess fleshing out the `compute-slots' protocol
from http://www.alu.org/mop/concepts.html#class-finalization-protocol
would be the thing.

I believe that technically you can already provide your own
`compute-slots' implementation, but you are probably missing some
definitions that would help you do so in a compatible manner.  Check it
out for yourself and give it a go, no need to wait on Guile people :)

Andy

On Sat 25 Apr 2015 04:05, David Pirotte <address@hidden> writes:

> 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
>
> (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")))
>
> address@hidden:~/alto/projects/stklos 15 $ stklos
> *   STklos version 1.10
>  *  Copyright (C) 1999-2011 Erick Gallesio - Universite de Nice 
> <address@hidden>
> * * [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
>
> (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"))
>
> address@hidden:~/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.)





reply via email to

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