From: Ron Garret
Subject: Two CLOS questions
Date: 
Message-ID: <rNOSPAMon-C82F35.14525807092006@news.gha.chartermi.net>
1.  How does one create a method object of the sort that one would pass 
as the second argument to a non-vacuous call to add-method?  (I put the 
non-vacuous qualifier in there because the obvious answer to the 
question is to use defmethod, but if you use defmethod then the method 
is already added and there is no need to call add-method.)

2.  Can someone please point me to an example of how one might use a 
non-standard method qualifier or (even better) multiple method 
qualifiers in a single method?

Thanks,
rg

From: Pascal Costanza
Subject: Re: Two CLOS questions
Date: 
Message-ID: <4mbmv1F5gjjtU1@individual.net>
Ron Garret wrote:
> 1.  How does one create a method object of the sort that one would pass 
> as the second argument to a non-vacuous call to add-method?  (I put the 
> non-vacuous qualifier in there because the obvious answer to the 
> question is to use defmethod, but if you use defmethod then the method 
> is already added and there is no need to call add-method.)

http://www.lisp.org/mop/concepts.html#init-generic

But note that different CLOS implementations support this only to 
various degrees. See http://common-lisp.net/project/closer/ for more 
details.

Of course it is possible to use plain Common Lisp to get at a method 
without adding it to a function in a way that would affect parts of a 
system that you don't want to affect. Simply create a dummy generic 
function of the right kind, define the method for it, and then remove it 
from that dummy function. It should be no problem to later add it to a 
different function. (Although this is not explicitly specified, I recall 
reading that this was one of the intentions of the CLOS designers. 
Better test this first.)

> 2.  Can someone please point me to an example of how one might use a 
> non-standard method qualifier or (even better) multiple method 
> qualifiers in a single method?

In AspectL, I have a method combination that allows you to override 
method definitions in previous dynamic scopes. Here, overriding means 
replacing those definitions completely so that they are never called in 
the current dynamic scope. You can choose not to override, and you can 
choose to override before/after/around methods. For the latter, it is 
nice to have multiple qualifiers, so I can say this:

(defmethod foo (...) ...)
(defmethod foo :around (...) ...)
(defmethod foo :override (...) ...)
(defmethod foo :override :around (...) ...)

There is another toy example in the source code of AspectL.

If I remember correctly, the HyperSpec also has an example.

Multiple qualifiers are not strictly necessary. I could have also 
introduced :override-around qualifiers, etc. But they were more 
convenient in this case.


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/
From: Ron Garret
Subject: Re: Two CLOS questions
Date: 
Message-ID: <rNOSPAMon-8AEDC2.16363807092006@news.gha.chartermi.net>
In article <··············@individual.net>,
 Pascal Costanza <··@p-cos.net> wrote:

> Ron Garret wrote:
> > 1.  How does one create a method object of the sort that one would pass 
> > as the second argument to a non-vacuous call to add-method?  (I put the 
> > non-vacuous qualifier in there because the obvious answer to the 
> > question is to use defmethod, but if you use defmethod then the method 
> > is already added and there is no need to call add-method.)
> 
> http://www.lisp.org/mop/concepts.html#init-generic
> 
> But note that different CLOS implementations support this only to 
> various degrees. See http://common-lisp.net/project/closer/ for more 
> details.
> 
> Of course it is possible to use plain Common Lisp to get at a method 
> without adding it to a function in a way that would affect parts of a 
> system that you don't want to affect. Simply create a dummy generic 
> function of the right kind, define the method for it, and then remove it 
> from that dummy function. It should be no problem to later add it to a 
> different function. (Although this is not explicitly specified, I recall 
> reading that this was one of the intentions of the CLOS designers. 
> Better test this first.)
> 
> > 2.  Can someone please point me to an example of how one might use a 
> > non-standard method qualifier or (even better) multiple method 
> > qualifiers in a single method?
> 
> In AspectL, I have a method combination that allows you to override 
> method definitions in previous dynamic scopes. Here, overriding means 
> replacing those definitions completely so that they are never called in 
> the current dynamic scope. You can choose not to override, and you can 
> choose to override before/after/around methods. For the latter, it is 
> nice to have multiple qualifiers, so I can say this:
> 
> (defmethod foo (...) ...)
> (defmethod foo :around (...) ...)
> (defmethod foo :override (...) ...)
> (defmethod foo :override :around (...) ...)
> 
> There is another toy example in the source code of AspectL.
> 
> If I remember correctly, the HyperSpec also has an example.
> 
> Multiple qualifiers are not strictly necessary. I could have also 
> introduced :override-around qualifiers, etc. But they were more 
> convenient in this case.
> 
> 
> Pascal

Thanks.

rg