[cl-faq] not exactly a FAQ, but sort of a GOTCHA: redefining methods

Larry Clapp larry at theclapp.org
Sat Dec 24 09:44:18 CST 2005


\faq{
  \question{Why doesn't the method I just wrote run when I call it?}
  \answer{Defining

	(defmethod foo ((bar t))
	  ...)

    doesn't automatically get rid of

	(defmethod foo ((bar integer))
	  ...)

    so if you call

	(foo 10)

    the \code{FOO} for \code{INTEGER} runs, not the (more general)
    \code{FOO} for \code{T}.

    This may seem obvious (if you already know CLOS :), but it's easy
    to forget that if you start with only the second one in your
    editor, and edit it into the first one and evaluate it, your Lisp
    environment still has both, even though your editor only has the
    new version.}}

\faq{
  \question{So how do I get rid of the old method definition?}
  \answer{See \code{REMOVE-METHOD} in the HyperSpec.
  
  You might think that you could just \code{DEFGENERIC FOO} and *all*
  of \code{FOO}'s methods would go away, but it doesn't work like
  that.  \code{DEFGENERIC} doesn't remove methods defined by
  \code{DEFMETHOD}, only methods defined by previous
  \code{DEFGENERIC}s.
  
  You could also, of course, just restart your Lisp and reload your
  files.  That works too.  :)}}



More information about the cl-faq mailing list