[Cuis] Copy vs Clone

Juan Vuletich juan at jvuletich.org
Wed May 13 21:24:09 CDT 2015


Hi Ken,

On 5/13/2015 7:41 PM, Ken.Dickey wrote:
> I am seeing a strange behavior.
>
> The simple way to see it is to make a child class of PartsBinMorph.  Call it, say, PartsBinTestMorph.
>
> Add a method #PartsBinTestMorph>>
>    aboutToGrab: aMorph
>
> 	^aMorph clone "parent has aMorph copy"
>
> WHen I obtain a PartsBinMorph from the new morph menu, then add, say, a ellipse morph, I get the expected behavior.  WHen I "drag the ellipse out", the hand gets a copy of the ellipse and the original ellipse remains where I can see it.
>
> But doing the same thing in a PartsBinTestMorph, I appear to grab the ellipse.
>
> Now it turns out that the original ellipse is still a submorph of the PartsBinTestMorph, but it's morphPosition seems to be set to some random value.
>
> I tried saving the original morphPosition, doing the clone, then resetting the saved morphPosition, but this does not change anything.
>
> Unfortunately, my copy of the blue book is saved in a box somewhere (I am moving), so I don't have a spec for #clone.
>
> Interestingly, this happens both on the ARM and Intel Cog Stack VMs.
>
> Can someone help me out to understand this?
>
> Thanks much,
> -KenD

Morphs should be copied using #copy.

#clone is almost the same as #shallowCopy (except if the primitive 
fails, in the implementation in Object). All the implementors and 
senders come from Squeak. I never questioned them (yet). In my copy of 
the purple book, on p.97 "Copying Objects" it only mentions #copy, 
#shallowCopy and #deepCopy. I removed #deepCopy from Cuis, but we also 
have #veryDeepCopy.

I found this:
http://wiki.squeak.org/squeak/2088
http://squeak-dev.squeakfoundation.narkive.com/nNy0QaLf/semantics-of-clone

None of this sounds really relevant to Cuis to me... I think it could be 
good to replace the calls to #clone with calls to #copy (by default) or 
#shallowCopy (if needed), and just remove #clone...

Does anybody know why #clone was added to Squeak?

Thanks,
Juan Vuletich




More information about the Cuis mailing list