guile-devel
[Top][All Lists]
Advanced

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

Re: goops - guile-clutter unexpected bug while using #:virtual slot allo


From: David Pirotte
Subject: Re: goops - guile-clutter unexpected bug while using #:virtual slot allocation for a <clutter-actor> subclass
Date: Sat, 7 Feb 2015 14:08:12 -0200

Hello Andy,

> > With the stable-2.0 or master branches, the current behavior is:
> > 
> >     scheme@(guile-user)> (use-modules (oop goops))
> >     scheme@(guile-user)> (define-class <a> ()
> >     ...   (foo #:getter foo #:init-keyword #:foo))
> >     scheme@(guile-user)> (define-class <b> (<a>))
> >     scheme@(guile-user)> (define obj (make <b> #:foo 34))
> >     scheme@(guile-user)> (define-method (foo (self <b>))
> >     ...   (pk "ahoy!")
> >     ...   (next-method))
> >     scheme@(guile-user)> (pk (foo obj))
> > 
> >     ;;; ("ahoy!")
> >     ERROR: In procedure scm-error:
> >     ERROR: No next method when calling #<<generic> foo (2)>
> >     with arguments (#<<b> 2c207e0>)
> > 
> >     Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> >     scheme@(guile-user) [1]> 
> 
> Yes, expected, but to me, it is because of what I just said here below.
> 
> > > In this case indeed, the only method that exists and is applicable is
> > > the getter foo that <a> defines and<b> inherits: there is no
> > > next-method and calling (next-method) would be a user bug, in my
> > > opinion too.
> > 
> > So, we should be precise with terminology :)  In GOOPS, subclasses do
> > not inherit accessor methods.  (There was a bug in which they would; I
> > fixed that.)  Each subclass gets its own accessor method defined, if and
> > only if it has the corresponding slot, and that method is not inherited.

Some are, some are not...:

;;; module a.scm starts here
(define-module (a)
  #:use-module (oop goops)
  #:export (<a>
            !v
            !width
            set-width))

(define-class <a> ()
  (v #:accessor !v
     #:init-keyword #:v
     #:allocation #:virtual
     #:slot-ref (lambda (self)
                  (pk "this is <a> v slot-ref, hello!"))
     #:slot-set! (lambda (self value)
                   (pk "this is <a> v slot-set!, hello!")))
  (width #:accessor !width #:init-keyword #:width #:init-value 0))

(define-method ((setter !width) (self <a>) width)
  (set-width self width))

(define-method (set-width (self <a>) width)
  ;; here comes complex code, computing earth orbit, captain's age...
  (pk "this is <a> !width setter method, hello!")
  (slot-set! self 'width width)
  width)
;;; module ends here

;;; module b.scm starts here
(define-module (b)
  #:use-module (oop goops)
  #:use-module (a)
  #:export (<b>)

  #:re-export (!v
               !width
               set-width))


(define-class <b> (<a>))
;;; module ends here

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)> 
scheme@(guile-user)> ,use (oop goops)
scheme@(guile-user)> ,use (b)
;;; note: source file ./b.scm
;;;       newer than compiled 
/home/david/.cache/guile/ccache/2.0-LE-8-2.0/usr/alto/projects/guile-tests/goops/setter-inheritance-bug/b.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling ./b.scm
;;; note: source file ./a.scm
;;;       newer than compiled 
/home/david/.cache/guile/ccache/2.0-LE-8-2.0/usr/alto/projects/guile-tests/goops/setter-inheritance-bug/a.scm.go
;;; compiling ./a.scm
;;; compiled 
/home/david/.cache/guile/ccache/2.0-LE-8-2.0/usr/alto/projects/guile-tests/goops/setter-inheritance-bug/a.scm.go
;;; compiled 
/home/david/.cache/guile/ccache/2.0-LE-8-2.0/usr/alto/projects/guile-tests/goops/setter-inheritance-bug/b.scm.go
scheme@(guile-user)> (make <b>)
$2 = #<<b> 2334760>
scheme@(guile-user)> (!v $2)

;;; ("this is <a> v slot-ref, hello!")
$3 = "this is <a> v slot-ref, hello!"
scheme@(guile-user)> (set! (!v $2) 'blue)

;;; ("this is <a> v slot-set!, hello!")
$4 = "this is <a> v slot-set!, hello!"
scheme@(guile-user)> (set! (!width $2) 10)
$5 = 10
scheme@(guile-user)> 

Cheers,
David


Attachment: pgpsqI6g3eGvY.pgp
Description: OpenPGP digital signature


reply via email to

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