On Tue, Aug 23, 2016 at 5:19 PM, Tommy Hofmann <[email protected]> wrote:

> Why do you think that deepcopy works on SelfReferential without defining
> deepcopy_internal? Line 8 of deepcopy.jl is: deepcopy(x) =
> deepcopy_internal(x, ObjectIdDict())
>

Because `deepcopy_internal` already handles this.

You shouldn't need to define deepcopy_internal for custom types in general,
unless your type needs special serialization support (e.g. if it has
pointer to C memory)


>
>
> On Tuesday, August 23, 2016 at 10:52:35 AM UTC+2, Chris Stook wrote:
>>
>> I created this simple example to try to understand deepcopy_internal.
>>
>> type SelfReferential
>>   obj::SelfReferential
>>
>>   SelfReferential() = (x = new(); x.obj = x)
>> end
>>
>> function deepcopy_internal(sr::SelfReferential, oidd::ObjectIdDict)
>> #  if haskey(oidd,sr)
>> #    return oidd[sr]
>> #  else
>>     new_obj = deepcopy_internal(sr,oidd)
>>     new_sr = sr(new_obj)
>>     oidd[sr] = new_sr
>>     return new_sr
>> #  end
>> end
>>
>> sr = SelfReferential()
>> deepcopy_sr = deepcopy(sr)
>>
>> This works, but deepcopy works on SelfReferential without defining
>> deepcopy_internal, so this isn't a good
>> example.
>>
>> How should this be modified so deepcopy_internal is required?
>>
>> Are the commented out lines of code necessary?
>>
>> Thanks,
>> Chris
>>
>>

Reply via email to