Hi --

On Sun, 12 Dec 2004, itsme213 wrote:

>> It's an interesting discussion.  Actually, even though I didn't say
>> anything and deleted it, I found the "custom freeze" idea particularly
>> intriguing.
>
> I thought "custom freeze" was the heart of what Nicolas started off with.

I think where I came in was discussing the freezing of local variable
bindings, which I didn't (and don't) like because it's such a
different kind of freezing from freezing a specific object (as done by
Kernel#freeze).  Which you disagreed with, etc. :-)

I certainly don't see any reason not to define custom freeze's for
specific objects, though there might be certain things you'd want to
watch out for.  One problem with the "deep freeze" might be that while
objects cannot share instance variables, they can share state by
having i.vars that refer to the same object.  So if it's in the
interest of one to freeze that deep object (as opposed to just
freezing the binding), but not in the interest of another, I guess
weird things could happen.

I'm thinking of something like (starting with non-weird case):

   class A
     attr_accessor :x
     def x_add(str)
       @x << str
     end
   end

   class B
     attr_accessor :y
   end

   a = A.new
   b = B.new

   shared = "hi"

   a.x = shared
   b.y = shared

   b.freeze            # freezes @y binding, but doesn't freeze @y

   a.x_add(" there")   # so this works

   puts b.y            # hi there

Now if you deep-froze b in such a way that @y (the object itself) was
frozen, then a would be in for a surprise when it called x_add.
(That's the "weird" case :-)  It's probably a fairly marginal
scenario, but it's definitely not impossible.


David

-- 
David A. Black
dblack / wobblini.net