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


Frederic Dumont <frederic.dumont@freeworld.be> writes:

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

Thanks to you and Russell for explaining this to me, I learnt
something about Scheme tonight.  This kind of behaviour looks rather
dangerous to me, especially since modifying a constant works most of
the time (I wonder how many times I used that "perfectly correct
behaviour").  But, as you point out, it is not, strictly speaking, a
bug in Guile or Goops.

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

Yes, it solves my problem.


-- 
Thierry Bézecourt

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