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
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 ----
> ;; 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
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
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
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/
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]
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 :-)
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
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.
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
* 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