Re: [CLOS] Ensuring a method exists
- From: Didier Verna <didier@xxxxxxxxxxxxx>
- Date: Wed, 27 Sep 2006 11:17:57 +0200
Lars Rune Nøstdal <larsnostdal@xxxxxxxxx> wrote:
This seems to work:
(defclass SomeBase ()
())
(defmethod initialize-instance :before ((some-base SomeBase) &key)
(format t "Checking for `foo': ~A~%"
(find-method #'foo '() (mapcar #'find-class
(list (type-of some-base)
(type-of some-base))))))
(defmethod foo ((a SomeBase) (b SomeBase))
(write-line "(foo SomeBase SomeBase)"))
(defclass SomeDerived (SomeBase)
())
That's a nice solution but it has one caveat (my question was probably
not clear enough about this): your trick checks for the existence of a method
only for the class you instanciate, and not for the subclasses.
So imagine having A <- B and creating only instances of B. The lack of method
for class A would go unnoticed. But I want the check for the whole hierarchy
(consider for instance that I'm using the AND method combination type and I'm
expecting an implementation for all the classes).
--
Check out my new jazz CD on http://www.didierverna.com/ !
Didier Verna EPITA / LRDE, 14-16 rue Voltaire Tel.+33 (1) 44 08 01 85
94276 Le Kremlin-Bicêtre, France Fax.+33 (1) 53 14 59 22
.
- Follow-Ups:
- Re: [CLOS] Ensuring a method exists
- From: Ken Tilton
- Re: [CLOS] Ensuring a method exists
- From: Lars Rune Nøstdal
- Re: [CLOS] Ensuring a method exists
- From: Lars Rune Nøstdal
- Re: [CLOS] Ensuring a method exists
- References:
- [CLOS] Ensuring a method exists
- From: Didier Verna
- Re: [CLOS] Ensuring a method exists
- From: Lars Rune Nøstdal
- [CLOS] Ensuring a method exists
- Prev by Date: Re: [CLOS] Ensuring a method exists
- Next by Date: Re: [CLOS] Ensuring a method exists
- Previous by thread: Re: [CLOS] Ensuring a method exists
- Next by thread: Re: [CLOS] Ensuring a method exists
- Index(es):
Relevant Pages
|