From: Karol Skocik
Subject: how do I fmakunbound a method specialized for a specific class?
Date: 
Message-ID: <1182968623.083911.123920@q75g2000hsh.googlegroups.com>
Hi,
  when I develop, sometimes I get into situation that, for example I
specialize

(defmethod initialize-instance :after ((object my-class) &key)
  ...)

but then I found that this is not the way to go, and I want to cancel
the effect of definition,
so that initialize-instance is not called when I create instance of
class my-class.

However, I can't do (fmakunbound 'initialize-instance) because:

1. that's the primary method, not the :after method
2. I want to undefine the after method specialized only for my-class

Until now the only way to do that is clean fasls and restart lisp
(SBCL 1.0.5 on Linux in my case)
but that's far from the way a lisper should do that.

Anybody knows  how to deal with that?

Thanks,
  Karol

From: Pascal Costanza
Subject: Re: how do I fmakunbound a method specialized for a specific class?
Date: 
Message-ID: <5efok6F38h83fU1@mid.individual.net>
Karol Skocik wrote:
> Hi,
>   when I develop, sometimes I get into situation that, for example I
> specialize
> 
> (defmethod initialize-instance :after ((object my-class) &key)
>   ...)
> 
> but then I found that this is not the way to go, and I want to cancel
> the effect of definition,
> so that initialize-instance is not called when I create instance of
> class my-class.
> 
> However, I can't do (fmakunbound 'initialize-instance) because:
> 
> 1. that's the primary method, not the :after method
> 2. I want to undefine the after method specialized only for my-class
> 
> Until now the only way to do that is clean fasls and restart lisp
> (SBCL 1.0.5 on Linux in my case)
> but that's far from the way a lisper should do that.
> 
> Anybody knows  how to deal with that?

a) Your development environment should support you here. For example, in 
LispWorks you invoke M-x Undefine while the cursor is in the method 
definition. You can also use LispWorks's generic function browser to 
undefine methods. Slime most probably has similar functionality, as do 
probably all other CL environments.

b) You can implement this yourself:

(let ((method (find-method #'initialize-instance
                 '(:after) (list (find-class 'my-class)))))
   (remove-method #'initialize-instance method))



Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Karol Skocik
Subject: Re: how do I fmakunbound a method specialized for a specific class?
Date: 
Message-ID: <1182970491.981743.71530@e9g2000prf.googlegroups.com>
> (let ((method (find-method #'initialize-instance
>                  '(:after) (list (find-class 'my-class)))))
>    (remove-method #'initialize-instance method))

That's it, thanks! Will check SLIME whether it has something...

Cheers,
  Karol
From: Zach Beane
Subject: Re: how do I fmakunbound a method specialized for a specific class?
Date: 
Message-ID: <m3myylw7ge.fsf@unnamed.xach.com>
Karol Skocik <············@gmail.com> writes:

> > (let ((method (find-method #'initialize-instance
> >                  '(:after) (list (find-class 'my-class)))))
> >    (remove-method #'initialize-instance method))
> 
> That's it, thanks! Will check SLIME whether it has something...

SLIME provides this when you inspect the generic function object
(e.g. via C-c I #'initialize-instance RET). It will provide a list of
specializations and have a clicky button for removing them.

Zach
From: Karol Skocik
Subject: Re: how do I fmakunbound a method specialized for a specific class?
Date: 
Message-ID: <1182971579.868750.83900@j4g2000prf.googlegroups.com>
On Jun 27, 8:58 pm, Zach Beane <····@xach.com> wrote:
> Karol Skocik <············@gmail.com> writes:
> > > (let ((method (find-method #'initialize-instance
> > >                  '(:after) (list (find-class 'my-class)))))
> > >    (remove-method #'initialize-instance method))
>
> > That's it, thanks! Will check SLIME whether it has something...
>
> SLIME provides this when you inspect the generic function object
> (e.g. via C-c I #'initialize-instance RET). It will provide a list of
> specializations and have a clicky button for removing them.
>
> Zach

Works perfect in SLIME, thanks!
From: Madhu
Subject: Re: how do I fmakunbound a method specialized for a specific class?
Date: 
Message-ID: <m31wfvvoqw.fsf@robolove.meer.net>
* Pascal Costanza <···············@mid.individual.net> :
| Karol Skocik wrote:
|>
|> (defmethod initialize-instance :after ((object my-class) &key)
|>   ...)
|>
|> but then I found that this is not the way to go, and I want to cancel
|> the effect of definition, so that initialize-instance is not called
|> when I create instance of class my-class.
|>
|
| a) Your development environment should support you here. For example,
| in LispWorks you invoke M-x Undefine while the cursor is in the method
| definition. You can also use LispWorks's generic function browser to
| undefine methods. Slime most probably has similar functionality, as do
| probably all other CL environments.
|
| b) You can implement this yourself:
|
| (let ((method (find-method #'initialize-instance
|                 '(:after) (list (find-class 'my-class)))))
|   (remove-method #'initialize-instance method))
|

Or you could wrap it up in a macro called UNDEFMETHOD.  That way you
just change the `(defmethod' to `(user:undefmethod' in the source file's
buffer and evaluate the s-expression using C-c C-c or C-M-x (in slime)
to remove that method.

Here is the implementation from my init file:

(defun parse-undefmethod-args (args)
  "Return values METHOD-QUALIFIERS and METHOD-SPECIALIZERS from
  parsing ARGS of the form (DEFMETHOD &REST ARGS)."
  (let (p q method-qualifiers specializers)
    (loop (cond ((atom (setq p (car args))) (push p method-qualifiers))
		(t (return)))	; now P is the specialized-lambda-list
       (setq args (cdr args)))
    (loop (when (null p) (return))
       (cond ((symbolp (setq q (car p)))
	      (case q
		((&aux &key &optional &rest &allow-other-keys) (return))
		(t (push T specializers)))) ; handle eql specializers:
	     ((consp (cadr q)) (push (cadr q) specializers))
	     (t (push (find-class (cadr q)) specializers)))
       (setq p (cdr p)))
    (values (nreverse method-qualifiers) (nreverse specializers))))

(defmacro undefmethod (function-name &rest args)
  `(let ((fdefn (fdefinition ',function-name)))
     (multiple-value-bind (qualifiers specializers)
	 (parse-undefmethod-args ',args)
       (let ((meth (find-method fdefn qualifiers specializers)))
	 (when meth (remove-method fdefn meth))))))

--
Madhu