This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: GOOPS: bug or strange feature in slot initialization


On Tue, Apr 18, 2000 at 08:56:35PM +0200, Thierry Bezecourt wrote:
> If a slot in a class is a list, and if that slot is initialized in the
> the initialize method, then all of the instances of this class will
> refer to the same list: if any of these instances modify the contents
> of the list, it will be seen in all the other objects, including those
> which will be created later.  Note that this is the same if the object
> is initialized with a #:init-value keyword in the class declaration
> (which could be considered as a feature since the class declaration
> block is evaluated only once).
<snip>
>   (define-method initialize ((x <foo>) args)
>     (next-method)
>     (set! (bar x) '(42)))

It is not a bug nor a feature.  According to the Revised(5) Report, '(42) is a
constant and it is an error to try to modify it.  Note that the report doesn't
say that an error should be detected.  So what you see is a perfectly correct
behaviour.

What you want is something like (set! (bar x) (cons 42 '())).

Regards,

-- 
    Frederic Dumont           / /  (_)__  __ ____  __
frederic.dumont@freeworld.be / /__/ / _ \/ // /\ \/ /
    PGP key 0711F125        /____/_/_//_/____/ /_/\_\  forever!!!!!!!
Linux? It's an OS, Jim, but not as we know it.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]