From: Eric Hodel Date: 2005-10-21T05:13:09+09:00 Subject: Re: DbC, const and freeze. 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 still think that the concept of constness doesn't fit Ruby well. > There are too many places where you can fiddle with state where you > normally (i.e. in other PL's) aren't allowed to. Adding #unfreeze > wouldn't help either because it would break the contract of freeze > that is used today - IOW code may break. Of course, Marshal.load(Marshal.dump(obj)) works for regular unfreeze as well. -- Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04