🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.clos
Article #150

undefmethod

#150
From: Clinton Hyde
Date: Wed, 19 Aug 1992 23:31
63 lines
2795 bytes
last week I asked about how to remove a method. here's the solution I
came up with in the end:

(defun undefmethod (gen-fn-name qualifiers-list specializer-type-names-list)
  
  "This will remove a method from a generic function. Only names are required.
Qualifiers-list is a list of things like :after, :before, :around.
`specializer-type-names-list` is a list of either class names or lists like (EQL _X_)."
  
  (flet ((get-specializer (name)
	   (if (symbolp name)
	       ;;THEN, just get the class.
	       (find-class name)
	     ;;else, it's either an eql specializer or something illegal. i think.
	     (if (and (listp name)
		      (equal (car name) 'eql))
		 ;;then, we're on this.
		 name
	       ;;else, we got something bad.
	       (error "~s is neither a class-name (symbol) or an eql specializer." name)
	       ))))

    (let (meth
	  (gen-fn (and (fboundp gen-fn-name)
		       (symbol-function gen-fn-name))))
      (unless (typep gen-fn 'generic-function)
	(format t "There is no generic function named ~S" gen-fn-name)
	(return-from undefmethod))
      (setq meth (find-method gen-fn qualifiers-list 
			      (mapcar #'get-specializer specializer-type-names-list)
			      ()))
      (unless meth 
	(error "There is no method for ~S with Qualifiers ~S and specializers ~S"
	       gen-fn-name qualifiers-list specializer-type-names-list))
      (remove-method gen-fn meth)))
  )

they way you use it:

(undefmethod 	'some-method-name 
		'(:after | :before | :around | nothing-at-all)
		'(class-name | class-name | (EQL something) ...))

works nicely. much help supplied by Gregor Kizcales, thanks to all
those who pointed out that it was supposed to be class-objects, not
just names. I wanted to only be using names on this.

also thanks to Gregor for introducing me the EQL-specializers, which
I'd not heard of before (they're probably right there in the book and
I haven't read those paragraphs). 

this is only tested in Allegro CL 4.1, but I'd guess it would work
elsewhere--I didn't cheat and use anything vendor-specific.

 -- clint
--

Clint Hyde		"Give me a LispM or give me death!" -- anonymous

Advanced Decision Systems	Internet:  chyde@chesapeake.ads.com
2111 Wilson Blvd #800
Arlington, VA 22201		(703) 875-0327
Technical Details
Message-ID: <CHYDE.92Aug19183128@pecos.ads.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!ads.com!chesapeake.ads.com!chesapeake!chyde

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!ads.com!chesapeake.ads.com!chesapeake!chyde
From: chyde@pecos.ads.com (Clinton Hyde)
Newsgroups: comp.lang.clos
Subject: undefmethod
Message-ID: <CHYDE.92Aug19183128@pecos.ads.com>
Date: 19 Aug 92 23:31:28 GMT
Sender: usenet@chesapeake.ads.com (USENET News)
Distribution: comp
Organization: Advanced Decision Systems, Mountain View, CA 94043, +1 (415)
 960-7300
Lines: 63