<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Aug 3, 2011, at 4:05 PM, Gary Byers wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br><br>On Wed, 3 Aug 2011, Alexander Repenning wrote:<br><br><blockquote type="cite">I need to remove all direct methods of a class.<br></blockquote><br>I assume that you mean that you need to remove these methods from the<br>generic functions that they're associated with.  If so, you want to<br>use REMOVE-METHOD, which both breaks that association between gf and<br>method and removes the method from the SPECIALIZER-DIRECT-METHODS  lists<br>of all of the method's specializers:<br><br>(defun remove-all-direct-methods (class)<br>  (dolist (method (SPECIALIZER-DIRECT-METHODS class))<br>    (REMOVE-METHOD method)))<br></div></blockquote><div><br></div><div><br></div><div><br></div><div>Thanks Gary. I had to add some code to find the gf. I am sure this could have been done more elegantly. I have been poking around <a href="http://www.lisp.org/mop/index.html">http://www.lisp.org/mop/index.html</a> I am glad it is online but it can be a bit confusing.</div><div><br></div><div>Anyway, this does that I need it to do:</div><div><br></div><div><div>(defun REMOVE-ALL-DIRECT-METHODS (class)</div><div>  (dolist (Generic-Function (ccl::specializer-direct-generic-functions class))</div><div>    (dolist (Method (copy-list (ccl::generic-function-methods Generic-Function)))</div><div>      (when (member Method (ccl::specializer-direct-methods class))</div><div>        ;; (format t "~%removing method ~A from generic function ~A" Method Generic-Function)</div><div>        (remove-method Generic-Function Method)))))</div><div><br></div><div><br></div><div><br></div><div>;; test case</div><div><br></div><div><div>(defclass animal ()</div><div>  ())</div><div><br></div><div>(defmethod make-sound ((self animal)) 'generic-sound)</div><div><br></div><div>(defclass dog (animal)</div><div>  ())</div><div><br></div><div>(defmethod make-sound ((self dog)) 'wuff)</div><div><br></div><div><br></div><div><br></div><div>(make-sound (make-instance 'dog))</div><div><br></div><div>(remove-all-direct-methods (find-class 'dog))</div><div><br></div><div>(make-sound (make-instance 'dog))</div><div><br></div></div></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><br><blockquote type="cite"><div><br>REMOVE-METHOD will call REMOVE-DIRECT-METHOD on the method and each of its<br>specializers, which means that it can destructively modify the list that<br>the DOLIST above is traversing.  That modification -probably- means<br>"sets the list to its CDR", but if you're at all paranoid about that you<br>could do:<br><br> ... (dolist (method (copy-list (SPECIALIZER-DIRECT-METHODS class)))) ...<br><br>The functions whose names are capitalized above are part of the MOP (and<br>those names are exported from the "CCL" and "OPENMCL-MOP" packages in CCL);<br>their behavior is described in<br><br><<a href="http://www.lisp.org/mop/index.html">http://www.lisp.org/mop/index.html</a>><br><br>which is essentially the same material that's available as chapters 5 and 6<br>of the book "The Art of the Metaobject Protocol", which is still in print:<br><br><<a href="http://www.amazon.com/Art-Metabobject-Protocol-Gregor-Kiczales/dp/0262610744">http://www.amazon.com/Art-Metabobject-Protocol-Gregor-Kiczales/dp/0262610744</a>><br><br><br><blockquote type="cite">The following code appears to remove all the direct methods yet they can still be invoked. Perhaps there is some caching going on? This is an evil CCL hack. Is this a caching problem? Is there a better, perhaps MOP based approach?<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">(defun REMOVE-ALL-DIRECT-METHODS (Class)<br></blockquote><blockquote type="cite">(dolist (method (slot-value Class 'ccl::direct-methods))<br></blockquote><blockquote type="cite">  (ccl::%remove-direct-methods method)))<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">;; example<br></blockquote><blockquote type="cite">(remove-all-direct-methods (find-class 'player_a_agent))<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">;; but direct player_a_agent method still executes.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">thanks,<br></blockquote><blockquote type="cite">Alex<br></blockquote><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">Openmcl-devel mailing list<br></blockquote><blockquote type="cite"><a href="mailto:Openmcl-devel@clozure.com">Openmcl-devel@clozure.com</a><br></blockquote><blockquote type="cite"><a href="http://clozure.com/mailman/listinfo/openmcl-devel">http://clozure.com/mailman/listinfo/openmcl-devel</a><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote></div></blockquote></div><br><div>
<span class="Apple-style-span" style="font-size: 12px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Prof. Alexander Repenning</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><br class="khtml-block-placeholder"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px">University of Colorado</p><p style="margin: 0.0px 0.0px 0.0px 0.0px">Computer Science Department</p><p style="margin: 0.0px 0.0px 0.0px 0.0px">Boulder, CO 80309-430</p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><br class="khtml-block-placeholder"></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica">vCard: <a href="http://www.cs.colorado.edu/~ralex/AlexanderRepenning.vcf">http://www.cs.colorado.edu/~ralex/AlexanderRepenning.vcf</a></font></p><br class="Apple-interchange-newline"></span></span>
</div>
<br></body></html>