guile-user
[Top][All Lists]
Advanced

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

Re: append! on a deep-cloned list slot


From: Brandon Invergo
Subject: Re: append! on a deep-cloned list slot
Date: Mon, 29 Apr 2019 11:12:07 +0100
User-agent: mu4e 1.2.0; emacs 26.2

Hi,

Thanks for your response.

address@hidden writes:

> Quoth the docs
>
> " -- generic: deep-clone
>   -- method: deep-clone (self <object>)
>      Return a “deep” clone of SELF.  The default method makes a deep
>      clone by allocating a new instance and copying or cloning slot
>      values from self to the new instance.  If a slot value is an
>      instance (satisfies ‘instance?’), it is cloned by calling
>      ‘deep-clone’ on that value.  Other slot values are copied either as
>      immediate values or by reference."
>
> Now a list isn't an object instance (i.e. it says #f to instance?).
> You'll either have to override your clone method to be more savvy
> or do something similar.

My reading of this was that a new instance is allocated and, since the
default #:allocation slot option is '#:instance', GOOPS "creates
separate storage for this slot in each new instance of the containing
class (and its subclasses)."  So I assumed that new storage is allocated
for the slot and the data is copied over, which meant that the whole
list was copied.

I guess the key words "by reference" carried more weight than I mentally
allocated to them.  GOOPS created separate storage for a new pointer,
not a whole list, and the only the address of the list was copied into
this pointer.  Tricky, but it makes sense I guess.

In my case, I can simply get rid of the deep-clones and instead create a
fresh instance and manually copy some of the slots from the old
instance.

Laziness and programmers are dangerous bedfellows.

Cheers,

--
-brandon



reply via email to

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