Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is a rather interesting question. Although, as <a href="https://stackoverflow.com/a/18619701/1281433">sds's answer</a> points out, you can use <code>(setf (find-class 'class-name) nil)</code> to make things like <code>(make-instance 'class-name)</code> stop working, that doesn't actually delete the class. You could, for instance, save the earlier result of <code>(find-class …)</code> somewhere else:</p> <pre class="lang-lisp prettyprint-override"><code>CL-USER&gt; (defclass foo () ()) #&lt;STANDARD-CLASS FOO&gt; CL-USER&gt; (defmethod show ((x foo)) (print "x is a foo")) STYLE-WARNING: Implicitly creating new generic function SHOW. #&lt;STANDARD-METHOD SHOW (FOO) {1002BFD321}&gt; CL-USER&gt; (defparameter *foo-class* (find-class 'foo)) *FOO-CLASS* CL-USER&gt; (show (make-instance 'foo)) "x is a foo" "x is a foo" CL-USER&gt; (setf (find-class 'foo) nil) NIL CL-USER&gt; (make-instance 'foo) ; Evaluation aborted on #&lt;SIMPLE-ERROR "There is no class named ~ .. {1002FDBC61}&gt;. CL-USER&gt; (make-instance *foo-class*) #&lt;#&lt;STANDARD-CLASS FOO&gt; {1003217F91}&gt; </code></pre> <p>I'm not sure whether there's actually any way to delete a class from the system, and it's not clear exactly what it would mean to do so, since it would have to address the issue of what to do with any existing instances of the class.</p> <p><code>(setf find-class)</code> also doesn't delete any methods that have been specialized for the class. Continuing the example just started, as we can still call <code>show</code> on instances of the class, and we can still retrieve the specialized methods:</p> <pre class="lang-lisp prettyprint-override"><code>CL-USER&gt; (show (make-instance *foo-class*)) "x is a foo" "x is a foo" CL-USER&gt; (find-method #'show '() (list *foo-class*)) #&lt;STANDARD-METHOD SHOW ((CLASS #&lt;STANDARD-CLASS FOO&gt;)) {1003A7D081}&gt; </code></pre> <p>However, you can remove applicable methods from a generic function using <a href="http://clhs.lisp.se/Body/f_rm_met.htm" rel="nofollow noreferrer">REMOVE-METHOD</a>:</p> <pre class="lang-lisp prettyprint-override"><code>CL-USER&gt; (remove-method #'show (find-method #'show '() (list *foo-class*))) #&lt;STANDARD-GENERIC-FUNCTION SHOW (0)&gt; CL-USER&gt; (show (make-instance *foo-class*)) ; Evaluation aborted on #&lt;SIMPLE-ERROR "~@&lt;There is no applicable method for the generic function ~2I~_~S~ .. {1002EA5731}&gt;. </code></pre> <p>In the Common Lisp Object System (CLOS), methods don't belong to classes, so it doesn't make sense to speak of "[undefining] a class and all of its methods." Rather, CLOS has generic functions, and the programmer defines methods that specialize the generic function. As the above examples show, while there may not be a portable way to undefine a class, you can remove the methods that are specialized for instances of that class, but you'll have to track down what they are. For more information, have a look at:</p> <ul> <li><a href="http://www.lispworks.com/documentation/HyperSpec/Body/07_.htm" rel="nofollow noreferrer">Chapter 7. Objects</a> of the HyperSpec and familiarize yourself with some of these concepts, because they do differ from what you find in many languages that are called object oriented. You might find a more gentle introduction in</li> <li><a href="http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html" rel="nofollow noreferrer">Chapter 16. Object Reorientation: Generic Functions</a> and <a href="http://www.gigamonkeys.com/book/object-reorientation-classes.html" rel="nofollow noreferrer">Chapter 17. Object Reorientation: Classes</a> from Peter Seibel's <a href="http://www.gigamonkeys.com/book/" rel="nofollow noreferrer"><em>Practical Common Lisp</em></a>. The book is a great reference, and the whole thing is available for free online.</li> </ul> <p>This topic has also been discussed on comp.lang.lisp:</p> <ul> <li><a href="https://groups.google.com/forum/#!topic/comp.lang.lisp/hzQ7RRTK4Lg" rel="nofollow noreferrer">undefining a class</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload