Re: [CLOS] Ensuring a method exists



Didier Verna wrote:

It was after a discussion with a friend about the problems of binary
methods in traditional objects systems. I was playing with the idea and trying
to see how those problems could be solved with CLOS.

Taking Wade's recent comment into account, that it is questionable why methods for all classes must exist, here is another rule that could be more useful: In a binary function, it could be useful to check that methods are always specialized on both arguments and always for the same classes. This could easily be checked in a method on add-method. Roughly like this:

(defclass binary-function (standard-generic-function)
()
(:metaclass funcallable-standard-class))

(defmethod add-method :before
((gf binary-function) method)
(assert (apply #'equal (method-specializers method))))

Any objections why one could want to break this requirement?


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
.