Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a defmethod for a struct

Tags:

common-lisp

I have 2 destructs: monster & orc. The orc includes monster. The generic monster has generic defmethods on it named monster-show & monster-hit. The orc has a specialized monster-hit but still keeps the generic monster-show. My problem is that I accidentally named the specialized method for the orc the wrong name (monster-show), so now when I try to use the generic monster-show, it runs code that it shouldn't (the wrongly named defmethod I compiled) instead of running the generic method.

Is there a way to get rid of a specialized defmethod in Slime + SBCL?

like image 384
Collin Bell Avatar asked Dec 23 '22 10:12

Collin Bell


2 Answers

If you don't have an IDE or such, you can use remove-method:

(remove-method #'monster-show
               (find-method #'monster-show
                            ()
                            (list (find-class 'orc))))
like image 184
Svante Avatar answered Jan 21 '23 10:01

Svante


Here’s how I would do it using the slime inspector:

Enter the generic function you want to modify:

CL-USER> #'monster-show
#<GENERIC FUNCTION: MONSTER-SHOW>

Move your cursor on to it and inspect the object by typing C-c C-v TAB

The inspector should show a list of methods for the function identified by their specialisers. Navigate to one and press the button to remove/unbind the method. You can click for this too.

Also by the description of your hierarchy it would probably be wiser to use real classes and not structs. Structs tens not to give a particularly big speedup compared to classes.

like image 26
Dan Robertson Avatar answered Jan 21 '23 09:01

Dan Robertson