From: parumaru
Subject: undefining generic functions
Date: 
Message-ID: <dlgacg$e86$1@news.cs.tu-berlin.de>
Hi,
I'm using sbcl+slime+ucw+... at the moment and unfortunatelly
discovered a "for me" big problem :(

I've created a method with defmethod like

(defmethod test (class)
  (do-something))

and after coding a little i found that the former definition
will not fit in, thus i wanted to change the method to:

(defmethod test (class &optional something-fancy)
  (do-something-more-fancier))

Guess... Right i wasn't able to compile it and
got an error.

Short: How may I change, delete, overwrite or ... the generic created by the
first definition in my image?

bye :)

From: Thomas A. Russ
Subject: Re: undefining generic functions
Date: 
Message-ID: <ymiwtj8p3va.fsf@sevak.isi.edu>
parumaru <······@gmx.net> writes:

> Hi,
> I'm using sbcl+slime+ucw+... at the moment and unfortunatelly
> discovered a "for me" big problem :(
> 
> I've created a method with defmethod like
> 
> (defmethod test (class)
>   (do-something))
> 
> and after coding a little i found that the former definition
> will not fit in, thus i wanted to change the method to:
> 
> (defmethod test (class &optional something-fancy)
>   (do-something-more-fancier))
> 
> Guess... Right i wasn't able to compile it and
> got an error.
> 
> Short: How may I change, delete, overwrite or ... the generic created by the
> first definition in my image?

Well, this doesn't apply to SBCL, based on a quick test, but other
common lisp implementations like Allegro or MCL have restart options in
the error that, if selected, will change the generic function with the
side effect of removing all of the existing methods.

That seems to me to be a bit friendlier than having to kill the function
manually and then recreate it.  (Like Pascal suggests in his answer).


-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Pascal Bourguignon
Subject: Re: undefining generic functions
Date: 
Message-ID: <874q6cxlxm.fsf@thalassa.informatimago.com>
parumaru <······@gmx.net> writes:

> Hi,
> I'm using sbcl+slime+ucw+... at the moment and unfortunatelly
> discovered a "for me" big problem :(
>
> I've created a method with defmethod like
>
> (defmethod test (class)
(defmethod test ((instance class))
>   (do-something))
>
> and after coding a little i found that the former definition
> will not fit in, thus i wanted to change the method to:
>
> (defmethod test (class &optional something-fancy)
(defmethod test ((instance class) &optional something-fancy)
>   (do-something-more-fancier))
>
> Guess... Right i wasn't able to compile it and
> got an error.
>
> Short: How may I change, delete, overwrite or ... the generic created by the
> first definition in my image?

(fmakunbound 'test)

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Litter box not here.
You must have moved it again.
I'll poop in the sink. 
From: drewc
Subject: Re: undefining generic functions
Date: 
Message-ID: <poPef.513712$oW2.196296@pd7tw1no>
parumaru wrote:
> Hi,
> I'm using sbcl+slime+ucw+... at the moment and unfortunatelly
> discovered a "for me" big problem :(
> 
> I've created a method with defmethod like
> 
> (defmethod test (class)
>   (do-something))
> 
> and after coding a little i found that the former definition
> will not fit in, thus i wanted to change the method to:
> 
> (defmethod test (class &optional something-fancy)
>   (do-something-more-fancier))
> 
> Guess... Right i wasn't able to compile it and
> got an error.
> 
> Short: How may I change, delete, overwrite or ... the generic created by the
> first definition in my image?

Use the slime inspector to inspect the function ,

C-c I #'test (or M-x slime-inspect)

and click :"[remove method]" on ALL the methods of the generic function. 
Then, you can use DEFGENERIC to redefine the function, and you'll be 
able to define methods on it.

The manual way of doing it would be to use REMOVE-METHOD, which involes 
FIND-METHOD. FIND-METHOD is, IMO, really ugly. It exposes some 
implemtation details that i'd rather not need when simply trying to 
remove a method..

Here's a quick and largely untested hack, DELMETHOD, that lets you 
simply change an F to an L to remove a method :

(defun find-specializers-using-lambda-list (specialized-lambda-list)
   (mapcar #'find-class
           (let (classes)
             (dolist (i specialized-lambda-list)
               (print i)
               (cond
                 ((consp i)
                  (print t)
                  (setf classes (cons (second i) classes)))
                 ((equalp (subseq (string i) 0 1) "&")
                  (return classes))
                 ((symbolp i)
                  (push t classes))))
             classes)))

(defun remove-method-using-lambda-list (fun
                                         specialized-lambda-list
                                         &optional qualifiers)
   (let ((specializers  (find-specializers-using-lambda-list
                         specialized-lambda-list)))

   (remove-method fun (find-method fun qualifiers specializers))))

(defmacro delmethod (name &rest definition)
   (if (keywordp (first definition))
       `(remove-method-using-lambda-list
         (function ,name)
         ',(second definition)
         ,(first definition))
       `(remove-method-using-lambda-list
         (function ,name)
         ',(first definition))))


But, in the end, the slime method works best.

drewc

-- 
Drew Crampsie
drewc at tech dot coop
  "... the most advanced use of lisp in the field of bass lure sales"
	-- Xach on #lisp
From: drewc
Subject: Re: undefining generic functions
Date: 
Message-ID: <OqPef.513717$oW2.215650@pd7tw1no>
drewc wrote:
> 
> But, in the end, the slime method works best.

Or, it seems, FMAKUNBOUND was well. I guess i remove methods more than i 
redefine the function and got all carried away :)


-- 
Drew Crampsie
drewc at tech dot coop
  "... the most advanced use of lisp in the field of bass lure sales"
	-- Xach on #lisp