[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: #:getter procedure returns unexpected value in GOOPS
From: |
Mark H Weaver |
Subject: |
Re: #:getter procedure returns unexpected value in GOOPS |
Date: |
Sun, 27 Apr 2014 21:12:12 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
David Pirotte <address@hidden> writes:
> Hi Mark,
>
>> > 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
>
>> Indeed, CLOS behaves as you expected...
>
> Are you sure about that?
Read this:
http://clhs.lisp.se/Body/07_ec.htm
In particular:
"In general, more than one class among C and its superclasses can
define a slot with a given name. In such cases, only one slot with
the given name is accessible in an instance of C, and the
characteristics of that slot are a combination of the several slot
specifiers, computed as follows: [...]"
Here's a transcript of an SBCL session I tried on Debian:
--8<---------------cut here---------------start------------->8---
This is SBCL 1.0.57.0.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (defclass foo ()
((a :initform 'foo :reader foo-a)
(b :initform 42)))
#<STANDARD-CLASS FOO>
* (defclass bar (foo)
((a :initform 'bar)))
#<STANDARD-CLASS BAR>
* (values (foo-a (make-instance 'foo)) (foo-a (make-instance 'bar)))
FOO
BAR
--8<---------------cut here---------------end--------------->8---
Unknown_lamer on #guile tried the same thing with a different
implementation of Common Lisp, and got the same answer.
Mark
Re: #:getter procedure returns unexpected value in GOOPS, Mark H Weaver, 2014/04/26