From: Andreas Politz
Subject: How to unbind specialized methods ?
Date: 
Message-ID: <1232593020.641797@arno.fh-trier.de>
I couldn't find an answer on the www ...

Suppose I have classes FOO and BAR and I define 2 methos like this:

(defmethod method ((foo foo) (bar bar))
   ...)

(defmethod method ((foo foo) whatever)
   ...)

Now I decide to just use the more generic one, but how do I
make the first one go away ?

-ap

From: Dimiter "malkia" Stanev
Subject: Re: How to unbind specialized methods ?
Date: 
Message-ID: <gl8o0r$spj$1@news.motzarella.org>
Andreas Politz wrote:
> 
> I couldn't find an answer on the www ...
> 
> Suppose I have classes FOO and BAR and I define 2 methos like this:
> 
> (defmethod method ((foo foo) (bar bar))
>   ...)
> 
> (defmethod method ((foo foo) whatever)
>   ...)
> 
> Now I decide to just use the more generic one, but how do I
> make the first one go away ?
> 
> -ap

(defstruct foo)
(defstruct bar)

;; Remove 'met1 method
(fmakunbound 'met1)

;; First put in place the more generic one
(defmethod met1 ((foo foo) whatever)
   (print "foo whatever"))
(met1 (make-foo) (make-bar))

;; Then the more specific one
(defmethod met1 ((foo foo) (bar bar))
   (print "foo bar"))
(met1 (make-foo) (make-bar))

;; Remove again the mroe generic one
(let ((method (find-method #'met1 () (mapcar #'find-class '(foo bar)))))
   (remove-method #'met1 method))

;; And print again
(met1 (make-foo) (make-bar))

;;;;;

;;;This is the output from Lispworks 5.1.2:

;;; Safety = 3, Speed = 1, Space = 1, Float = 1, Interruptible = 0
;;; Compilation speed = 1, Debug = 2, Fixnum safety = 3
;;; Source level debugging is on
;;; Source file recording is  on
;;; Cross referencing is on
; (TOP-LEVEL-FORM 0)
; (SUBFUNCTION MAKE-FOO (DEFSTRUCT FOO))
; (SUBFUNCTION MAKE-FOO (DEFSTRUCT FOO))
; (SUBFUNCTION MAKE-BAR (DEFSTRUCT BAR))
; (SUBFUNCTION MAKE-BAR (DEFSTRUCT BAR))
; (TOP-LEVEL-FORM 3)
; (METHOD MET1 (FOO T))
; (TOP-LEVEL-FORM 5)

"foo whatever"
; (METHOD MET1 (FOO BAR))
; (TOP-LEVEL-FORM 7)

"foo bar"
; (TOP-LEVEL-FORM 8)
; (TOP-LEVEL-FORM 9)

"foo whatever"

---- Press Space to continue ----
From: Dimiter "malkia" Stanev
Subject: Re: How to unbind specialized methods ?
Date: 
Message-ID: <gl8o3b$spj$2@news.motzarella.org>
> ;; Remove 'met1 method
> (fmakunbound 'met1)

This should read as: "Remove 'met1 generic-function: (and all methods 
that it contains) - this is just to give us a fresh start
From: Andreas Politz
Subject: Re: How to unbind specialized methods ?
Date: 
Message-ID: <1232597549.795858@arno.fh-trier.de>
Dimiter "malkia" Stanev wrote:
>> ;; Remove 'met1 method
>> (fmakunbound 'met1)
> 
> This should read as: "Remove 'met1 generic-function: (and all methods 
> that it contains) - this is just to give us a fresh start

Yes, thanks for the lisp code. remove-method was just to obvious.

-ap
From: ······@corporate-world.lisp.de
Subject: Re: How to unbind specialized methods ?
Date: 
Message-ID: <4fb4b2f0-7f02-409c-b7a0-ce228c88dc06@k1g2000prb.googlegroups.com>
On 22 Jan., 05:11, Andreas Politz <·······@fh-trier.de> wrote:
> Dimiter "malkia" Stanev wrote:
> >> ;; Remove 'met1 method
> >> (fmakunbound 'met1)
>
> > This should read as: "Remove 'met1 generic-function: (and all methods
> > that it contains) - this is just to give us a fresh start
>
> Yes, thanks for the lisp code. remove-method was just to obvious.
>
> -ap

For LispWorks IDE users:

* use the generic function browser (>Windows>Tools>)
  browse a generic function
  select a method
  choose >methods>Undefine   (from the menu or the right-click menu)

or

* use the LispWorks editor
  place the cursor on the method definition
  M-x undefine    then removes the method
From: Pascal Costanza
Subject: Re: How to unbind specialized methods ?
Date: 
Message-ID: <6trbilFbrtdjU2@mid.individual.net>
Dimiter "malkia" Stanev wrote:
>> ;; Remove 'met1 method
>> (fmakunbound 'met1)
> 
> This should read as: "Remove 'met1 generic-function: (and all methods 
> that it contains) - this is just to give us a fresh start

A little bit of nitpicking here: fmakunbound doesn't remove functions, 
just the assocation between a symbol and a function. The function 
continues to exist, unless it can be garbage collected. (This can lead 
to surprises depending on how you used the function before.)


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: Dimiter "malkia" Stanev
Subject: Re: How to unbind specialized methods ?
Date: 
Message-ID: <glaht2$mlb$1@news.motzarella.org>
Pascal Costanza wrote:
> Dimiter "malkia" Stanev wrote:
>>> ;; Remove 'met1 method
>>> (fmakunbound 'met1)
>>
>> This should read as: "Remove 'met1 generic-function: (and all methods 
>> that it contains) - this is just to give us a fresh start
> 
> A little bit of nitpicking here: fmakunbound doesn't remove functions, 
> just the assocation between a symbol and a function. The function 
> continues to exist, unless it can be garbage collected. (This can lead 
> to surprises depending on how you used the function before.)

Gotcha! Yup - I guess if the method/generic-function is still active (in 
the stack, another thread, or kept somewhere).

But I guess, this is what he actually wants, I mean even if that 
function is still active, the disconnection is already made, and CLOS 
won't reuse it.

Another thing, that makes me feel really warm about Common Lisp - it's 
my Clay Language - [insert here a cool image of Wallace & Grommit]
From: Stanisław Halik
Subject: Re: How to unbind specialized methods ?
Date: 
Message-ID: <gl8q4j$18hs$1@opal.icpnet.pl>
thus spoke Andreas Politz <·······@fh-trier.de>:

> Suppose I have classes FOO and BAR and I define 2 methos like this:
> (defmethod method ((foo foo) (bar bar))
>   ...)
> (defmethod method ((foo foo) whatever)
>   ...)
> Now I decide to just use the more generic one, but how do I
> make the first one go away ?

Fire up the SLIME Inspector on the datum #'foo, then click on the method
to be removed. Easy enough :-)
From: Andreas Politz
Subject: Re: How to unbind specialized methods ?
Date: 
Message-ID: <1232597401.379437@arno.fh-trier.de>
Stanis?aw Halik wrote:
> thus spoke Andreas Politz <·······@fh-trier.de>:
> 
>> Suppose I have classes FOO and BAR and I define 2 methos like this:
>> (defmethod method ((foo foo) (bar bar))
>>   ...)
>> (defmethod method ((foo foo) whatever)
>>   ...)
>> Now I decide to just use the more generic one, but how do I
>> make the first one go away ?
> 
> Fire up the SLIME Inspector on the datum #'foo, then click on the method
> to be removed. Easy enough :-)

That would be preferable, but first I suppose you ment #'method
and second this throws an error about some missing slot. I guess
this doesn't work with my slime-version and lispworks ?

-ap
From: Peder O. Klingenberg
Subject: Re: How to unbind specialized methods ?
Date: 
Message-ID: <ksljt3g0jr.fsf@beto.netfonds.no>
Andreas Politz <·······@fh-trier.de> writes:

> this throws an error about some missing slot. I guess this doesn't
> work with my slime-version and lispworks ?

Sounds like an ancient bug in the lispworks-specific bits of slime's
fancy-inspector.  That bug was fixed in the slime repository a few
days ago, after patches had been floating around the slime mailinglist
for years.

See the subthread starting at
<http://thread.gmane.org/gmane.lisp.slime.devel/8065/focus=8086> for
details.

...Peder...
-- 
This must be Thursday.  I never could get the hang of Thursdays.
From: Andreas Politz
Subject: Re: How to unbind specialized methods ?
Date: 
Message-ID: <1232730380.278470@arno.fh-trier.de>
Peder O. Klingenberg wrote:
> Andreas Politz <·······@fh-trier.de> writes:
> 
>> this throws an error about some missing slot. I guess this doesn't
>> work with my slime-version and lispworks ?
> 
> Sounds like an ancient bug in the lispworks-specific bits of slime's
> fancy-inspector.  That bug was fixed in the slime repository a few
> days ago, after patches had been floating around the slime mailinglist
> for years.
> 
> See the subthread starting at
> <http://thread.gmane.org/gmane.lisp.slime.devel/8065/focus=8086> for
> details.
> 
> ...Peder...

Yes, I updated slime and it works now.

Thanks.

-ap
From: Madhu
Subject: Re: How to unbind specialized methods ?
Date: 
Message-ID: <m3bpu0owh2.fsf@moon.robolove.meer.net>
* Andreas Politz <·················@arno.fh-trier.de> :
Wrote on Thu, 22 Jan 2009 03:55:57 +0100:

| (defmethod method ((foo foo) (bar bar)) ...)
| (defmethod method ((foo foo) whatever) ...)
|
| Now I decide to just use the more generic one, but how do I
| make the first one go away ?

<URL:http://www.lispworks.com/documentation/HyperSpec/Body/f_rm_met.htm>

You could search for UNDEFMETHOD on CLL or perhaps use the portable
UNDEFMETHOD in swank-undefmethod.lisp I posted on the slime mailing list:

<URL:http://permalink.gmane.org/gmane.lisp.slime.devel/7974>

--
Madhu