Skip to content

Undefine (remove) a method that was associated with a generic function #42

Description

@vindarel

You created methods, but you want to remove one from the running image. There is no default way.

(defmacro undefmethod (name &rest args)
  "Undefine a method which was previously associated with a generic function.

Caveat: it doesn't work for EQL specialisers."
  ;; @shinmera
  ;; https://www.reddit.com/r/Common_Lisp/comments/1766lmu/cl_newbie_questions/
   (flet ((lambda-keyword-p (symbol)
            (find symbol lambda-list-keywords)))
     (destructuring-bind (qualifiers args) (loop for thing = (pop args)
                                                 until (listp thing)
                                                 collect thing into qualifiers
                                                 finally (return (list qualifiers thing)))
       `(remove-method
         #',name
         (find-method
          #',name
          ',qualifiers
          (mapcar #'find-class
                  ',(loop for arg in args
                          until (lambda-keyword-p arg)
                          collect (if (listp arg) (second arg) T))))))))

Alexander adds:

I usually open generic function in the SLY inspector and remove needed methods from there.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions