Article View: comp.lang.clos
Article #87Re: no-applicable-method
From: Thomas Kirk
Date: Thu, 16 Apr 1992 09:05
Date: Thu, 16 Apr 1992 09:05
45 lines
2100 bytes
2100 bytes
From: barmar@think.com (Barry Margolin)
Sender: commonloops-request@cis.ohio-state.edu
References: <odvAqcy00iQQRD=Fo6@andrew.cmu.edu>state
Subject: Re: no-applicable-method
. . .
But it might be better to use an OO technique. Define subclasses of
GENERIC-FUNCTION that delegate on specific arguments, and use this as the
metaclass of the generic functions that you want to be delegated.
Something like:
(defclass delegatable-normal-gf (generic-function))
(defmethod no-applicable-method ((gf delegatable-normal-gf) &rest args)
(let ((prototype (prototype (first args))))
(if prototype
(apply gf prototype (cdr args))
(call-next-method))))
(defclass delegatable-setf-gf (generic-function))
(defmethod no-applicable-method ((gf delegatable-setf-gf) new-value object)
(let ((prototype (prototype object)))
(if prototype
(apply gf prototype new-value)
(call-next-method))))
However, this won't work if you're trying to do this to generic functions
that you don't define yourself, since you can't override their metaclasses.
this will work fine. assuming that you can get at the generic functions,
just change the class of the generic function object, like so:
(defclass delegatable-normal-gf (standard-generic-function)
()
(:metaclass clos:funcallable-standard-class))
(defgeneric frob (thing))
(let ((gf (symbol-function 'frob)))
(change-class gf (find-class 'delegatable-normal-gf)))
(symbol-function 'frob) ==> #<DELEGATABLE-NORMAL-GF FROB 22011004736>
Technical Details
Message-ID:
<19920416170513.9.TK@PETZL.research.att.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!HUNNY.research.ATt.COM!tkReferences:
<kupqlnINNkol@early-bird.think.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.clos Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!HUNNY.research.ATt.COM!tk From: tk@HUNNY.research.ATt.COM (Thomas Kirk) Subject: Re: no-applicable-method Message-ID: <19920416170513.9.TK@PETZL.research.att.com> Sender: daemon@cis.ohio-state.edu Reply-To: tk@research.att.com Organization: The Ohio State University Department of Computer and Information Science References: <kupqlnINNkol@early-bird.think.com> Date: Thu, 16 Apr 1992 09:05:00 GMT Lines: 46