[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: :after redefinitions



At  5:33 PM 93.09.22 -0600, osiris wrote:
>[2] Say I have a file that defines an after method.  Is there any way to
>clear a previous definition for that after method so that reloading the
>file that defines the after method will replace the old definition instead
>of agumenting it?

>From Duncan Smith at Flavors...

(defmacro undefmethod (name &rest etc)
  "The arguments are identical to DEFMETHOD.
When you are going to delete a method simply
ad UN in front of DEFMETHOD and evaluate it."
  `(let* ((etc ',etc)
          (ll-tail (member-if #'consp etc))
          (qualifiers (ldiff etc ll-tail))
          (specializers
           (loop for argspec in (car ll-tail)
                 when (member argspec lambda-list-keywords)
                 do (loop-finish)
                 collect (if (consp argspec)
                           (let ((spec (cadr argspec)))
                             (cond ((symbolp spec)
                                    (find-class spec))
                                   ((and (consp spec)
                                         (eq (car spec) 'eql))
                                    (list 'eql (eval (cadr spec))))
                                   (t (error "Bogus: ~S" argspec))))
                           (find-class t))))
          (function (symbol-function ',name))
          (method (find-method function qualifiers specializers nil)))
     (if method
       (remove-method function method)
       (warn "Can't (FIND-METHOD #'~S '~S '~S)" ',name qualifiers
specializers))))

The only problem in using this is that you've usually hacked on the arglist
before remembering to use the macro. So, 

from Yamagen at Flavors...

(in-package "INSPECTOR")

(defvar inspector-commands nil)

(defmethod inspector-commands :around (x)
  (if inspector-commands
    (call-next-method)
    (let ((inspector-commands t))
      (append
       (call-next-method)
       (typecase x
         (gf-inspector
          (list
           (list
            "REMOVE METHOD"
            #'(lambda ()
                (let* ((iv (inspector-view x))
                       (s (selection iv)))
                  (if s
                    (let* ((m (cached-line-n iv s))
                           (g (method-generic-function m)))
                      (when (y-or-n-dialog
                             (format nil "~s~%Remove the method?" m))
                        (remove-method g m)
                        (resample-it)))
                    (ed-beep))))))))))))

which adds a menu item to generic-function inspector windows to remove
selected methods.

e