<html><body>
<p><tt>xotcl-bounces@alice.wu-wien.ac.at wrote on 03/15/2006 04:23:28 AM:<br>
<br>
> <br>
> On 15 Mar 2006, at 12:17, Gustaf Neumann wrote:<br>
> ><br>
> <br>
> I am actually quite surprised to find that the move operation calls <br>
> the destructor. This is not mentioned on the reference manual and <br>
> does, in fact, seem counter-intuitive. A move is a move, nothing is <br>
> being destroyed, so why call the destructor? <br>
</tt><br>
<tt>I agree. A move operation didn't imply object destruction to me, either. </tt><br>
<br>
<tt>> I understand that the <br>
> operation is actually quite expensive, due to current Tcl internals, <br>
> but is there any reason why a destructor should be called? If we want <br>
> a method called for a move operation, surely it would be simple to <br>
> define that a "beingMoved" method is then called.</tt><br>
<br>
<tt>I'm guessing that xotcl::object's "destroy" method does all the heavy lifting (cleaning up the source of the move). What would happen if the default move implementation was to change the source object's class to xotcl::object before invoking destroy? This way it would continue to use the xotcl::object's "destroy" implementation for cleanup purposes without invoking all of the subclass destroy methods, and derived classes wouldn't perceive move as a destroy operation. Would this have bad side-effects?</tt><br>
<br>
<tt>> > it is quite simple<br>
> > for a poweruser of xotcl to overload copy/move and add applicaton<br>
> > specific addtional behavior to it. if one does not like the side- <br>
> > effects<br>
> > of destroy in a move, a custom move operation can set in instance<br>
> > variable "__during_move__" and query this from the destroy<br>
> > method to change its behavior.</tt><br>
<br>
<tt>While I'm no poweruser, I did get the guard mechanism to work. Here it is for completeness sake. (Is there an easy way to search the mail archives? Maybe this will help someone else...)</tt><br>
<br>
<tt># move doesn't do what I expect. It's not simply a move, it's</tt><br>
<tt># actually a deep copy followed by a destroy. I want to reclaim the</tt><br>
<tt># object on destroy, but not the imputed destroy from the move</tt><br>
<tt># operation. So flag that the destroy is happening because of a move</tt><br>
<tt># so the destroy reclamation doesn't happen, and then reset the flag</tt><br>
<tt># in the new copy.</tt><br>
<tt>TrackingMixin instproc move {dest} {</tt><br>
<tt> my set _ismoving_ 1</tt><br>
<tt> next</tt><br>
<tt> $dest unset _ismoving_</tt><br>
<tt>}</tt><br>
<tt>TrackingMixin instproc destroy {args} {</tt><br>
<tt> if {[my info vars _ismoving_] eq ""} {</tt><br>
<tt> # true destroy, do true destroy things...</tt><br>
<tt> } else {</tt><br>
<tt> next</tt><br>
<tt> }</tt><br>
<tt>}</tt><br>
<br>
<br>
<tt>        Scott</tt></body></html>