[Prev][Next][Index][Thread]

Re: Object lifetime management



On Thu, 12 Jul 2001 11:04:06 +0100, Rob Myers <robmyers@mac.com> wrote:

> In Dylan, next-method() will do this. In C++, forgetting to make a 
> destructor virtual will not do this. I've seen *experienced* C++ gods 
> forget to do this.

Some times it is nice to have extra support though. For example, in Common
Lisp one can define "after methods" which don't need to call the next
method explicitly. Or one can even define generic functions whose methods
combine in arbitrary ways. Eg I used to use "progn" method combination for
resource cleanup.

We could do that with macros in Dylan, eg:

define after-method() cleanup ( my-object :: <my-class> ) => ()
  release-the-resource( my-object );
end method;

// which expands into:

define method cleanup ( my-object :: <my-class> ) => ()
  next-method();
  release-the-resource( my-object );
end method;

// or

define after-method(\+) countup ( my-object :: <my-class> )
 => ( r :: <integer> )
  count-the-resources( my-object );
end method;

define method countup ( my-object :: <my-class> )
 => ( r :: <integer> )
  next-method() + count-the-resources( my-object );
end method;

This macro is of course an exercise for the reader...

__Jason



References: