[Cuis] [SOLVED] Re: Copy vs Clone

Juan Vuletich juan at jvuletich.org
Thu May 14 09:03:29 CDT 2015


Hi Ken,

On 5/14/2015 1:16 AM, Ken.Dickey wrote:
> On Wed, 13 May 2015 23:25:37 -0300
> Juan Vuletich<juan at jvuletich.org>  wrote:
>
>> Well, but why do #clone or #shallowCopy? Isn't #copy ok?
> Not when using closures with state.
>    Error: can only serialize clean closures
>
> Morph>>copy serializes, but does not have to.
> We can make all closures serializable (e.g. KaliScheme does this to export closures over the network).  This is clean but it is still a bit of work.

Interesting! I wasn't aware of KaliScheme. I believe Fuel also does it. 
The problem with this is that it is easy to clone the whole Smalltalk 
image inadvertently.

> The original Object>>copy would work where I implement postCopy to set location to a new MorphicTranslation.
>
> Object>>copy
>      ^self shallowCopy postCopy

But the problem with this is that the original and the copy would share 
that state embedded in the closure... They would also share submorphs, etc.

Can you help me reproduce the problem with the closure? I think the best 
would be to make that closure a "clean" one, storing any needed state in 
the morph (maybe as properties), and accessing it via messages to self...

Steps to reproduce, or a pre-built image (via private email) or any 
other means would be ok.

Sometimes I think it would be nicer if all closures were clean. I'm not 
really sure what would we lose with such restriction...

Cheers,
Juan Vuletich




More information about the Cuis mailing list