clos - Undefining a class and all its methods in Common Lisp -


i undefine class , of methods after quite thorough search on googlore have been unable find clue how this.

i using implementation of commmon lisp called ccl (clozure cl).

this rather interesting question. although, sds's answer points out, can use (setf (find-class 'class-name) nil) make things (make-instance 'class-name) stop working, doesn't delete class. could, instance, save earlier result of (find-class …) somewhere else:

cl-user> (defclass foo () ()) #<standard-class foo> cl-user> (defmethod show ((x foo))            (print "x foo")) style-warning: implicitly creating new generic function show. #<standard-method show (foo) {1002bfd321}> cl-user> (defparameter *foo-class* (find-class 'foo)) *foo-class* cl-user> (show (make-instance 'foo))  "x foo"  "x foo" cl-user> (setf (find-class 'foo) nil) nil cl-user> (make-instance 'foo) ; evaluation aborted on #<simple-error "there no class named ~ .. {1002fdbc61}>. cl-user> (make-instance *foo-class*) #<#<standard-class foo> {1003217f91}> 

i'm not sure whether there's way delete class system, , it's not clear mean so, since have address issue of existing instances of class.

(setf find-class) doesn't delete methods have been specialized class. continuing example started, can still call show on instances of class, , can still retrieve specialized methods:

cl-user> (show (make-instance *foo-class*))  "x foo"  "x foo" cl-user> (find-method #'show '() (list *foo-class*)) #<standard-method show ((class #<standard-class foo>)) {1003a7d081}> 

however, can remove applicable methods generic function using remove-method:

cl-user> (remove-method #'show (find-method #'show '() (list *foo-class*))) #<standard-generic-function show (0)> cl-user> (show (make-instance *foo-class*)) ; evaluation aborted on #<simple-error "~@<there no applicable method generic function ~2i~_~s~ .. {1002ea5731}>. 

in common lisp object system (clos), methods don't belong classes, doesn't make sense speak of "[undefining] class , of methods." rather, clos has generic functions, , programmer defines methods specialize generic function. above examples show, while there may not portable way undefine class, can remove methods specialized instances of class, you'll have track down are. more information, have at:

this topic has been discussed on comp.lang.lisp:


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -