From: Robert Klemme Date: 2005-10-21T05:36:59+09:00 Subject: Re: DbC, const and freeze. Eric Hodel wrote: > On Oct 20, 2005, at 7:40 AM, Robert Klemme wrote: > >> 2005/10/20, Ryan Leavengood : >> >>> On 10/19/05, John Carter wrote: >>> >>>> For example, look at this hole... >>>> irb >>>> irb(main):001:0> a = [[1,2],[3,4]] >>>> => [[1, 2], [3, 4]] >>>> irb(main):002:0> a.freeze >>>> => [[1, 2], [3, 4]] >>>> irb(main):003:0> a << [9] >>>> RuntimeError: can't modify frozen array >>>> from (irb):3:in `<<' >>>> from (irb):3 >>>> from :0 >>>> irb(main):004:0> a[0]<<1 >>>> => [1, 2, 1] >>>> irb(main):005:0> a >>>> => [[1, 2, 1], [3, 4]] >>>> irb(main):006:0> >>>> >>>> Even though "a" was frozen, I still could modify the things "a" >>>> contained. >>>> >>> >>> Fair enough. How about this: >>> >> >> >> Apart from the fact that deep_unfreeze is missing... > > No, its not (well, you don't get the original back). > > Marshal.load(Marshal.dump(obj)) I meant, it's missing from the sample implementation. But: Marshal does something completely different: creating a copy is something different from temporary freezing an instance's (or instance graph's) state. It starts with different identities and doesn't stop at performance... You *can* use that in certain scenarios but I doubt that it's a full replacement for constness. Kind regards robert