Association postcopy (Pharo 3)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Association postcopy (Pharo 3)

Hartmut
Hi,

the Dictionary>>postCopy comment reads:
"Must copy the associations, or later store will affect both the
original and the copy

However Association(Object)>>copy will neither copy 'key' (thats what I
expect) nor 'value' (that makes the copy fail).
I checked an older version of Squeak and VisualWorks 7 and found that
also there Association misses a postCopy.

My workaround for a Dictionary copy reads "...  associationsDo: [ :a | a
value: a value copy ] ".

Does anybody know why Association does not contain this code in a
postCopy method ?

Thanks,
Hartmut

--
Hartmut Krasemann

Königsberger Str. 41 c

D 22869 Schenefeld

Tel. 040.8307097

Mobil 0171.6451283

[hidden email]



smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Association postcopy (Pharo 3)

Sven Van Caekenberghe-2

> On 05 Apr 2015, at 12:06, Hartmut <[hidden email]> wrote:
>
> Hi,
>
> the Dictionary>>postCopy comment reads:
> "Must copy the associations, or later store will affect both the original and the copy

You interpret the comment incorrectly: it talks about the association itself, not the value that it holds. Without Dictionary>>#postCopy associations end up being shared between the original and the copy; when you overwrite an existing entry in the original dictionary, you would also change the copy - which you do not want.

You seem to be expecting that the values that you put in should also be copied, but that is your responsibility, not that of the data structure. Think about it, this copying does not happen in arrays or ordered collections either.

Does that make sense ?

> However Association(Object)>>copy will neither copy 'key' (thats what I expect) nor 'value' (that makes the copy fail).
> I checked an older version of Squeak and VisualWorks 7 and found that also there Association misses a postCopy.
>
> My workaround for a Dictionary copy reads "...  associationsDo: [ :a | a value: a value copy ] ".
>
> Does anybody know why Association does not contain this code in a postCopy method ?
>
> Thanks,
> Hartmut
>
> --
> Hartmut Krasemann
>
> Königsberger Str. 41 c
>
> D 22869 Schenefeld
>
> Tel. 040.8307097
>
> Mobil 0171.6451283
>
> [hidden email]
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Association postcopy (Pharo 3)

Hartmut
Am 05.04.15 um 12:34 schrieb Sven Van Caekenberghe:
>> the Dictionary>>postCopy comment reads:
>> "Must copy the associations, or later store will affect both the original and the copy
> You interpret the comment incorrectly: it talks about the association itself, not the value that it holds. Without Dictionary>>#postCopy associations end up being shared between the original and the copy; when you overwrite an existing entry in the original dictionary, you would also change the copy - which you do not want.
>
> You seem to be expecting that the values that you put in should also be copied, but that is your responsibility, not that of the data structure. Think about it, this copying does not happen in arrays or ordered collections either.
>
> Does that make sense ?
Yes, thanks

--
Hartmut Krasemann

Königsberger Str. 41 c

D 22869 Schenefeld

Tel. 040.8307097

Mobil 0171.6451283

[hidden email]



smime.p7s (5K) Download Attachment