From: Pascal Costanza
Subject: A method combination can depend on what?
Date: 
Message-ID: <aq3sij$g98$1@newsreader2.netcologne.de>
Hi,

I have some difficulty in sorting out what an effective method can 
depend on when you want to write your own method combinations.

The HyperSpec makes the following statements.

* "The role of each method in the effective method is determined by its 
qualifiers and the specificity of the method." (7.6.6.1.3)

* "To compare the precedence of two methods, their parameter 
specializers are examined in order." (7.6.6.1.2)

So the following interpretation seems to be correct.

* An effective method is allowed to depend only on the qualifiers and 
parameter specializers of all involved methods. In other words: It can 
only depend on _static_ properties of these methods.

* Especially, an effective method must not depend on (or vary according 
to) dynamic state like global variables or concrete parameters of the 
method.

Is this correct, or am I missing something?

So, for example, the following method combination would be incorrect.

(define-method-combination mycomb ()
                            ((methods *))
   (:arguments arg0)
   (if (member arg0 *special-cases*)
     `(call-method ,(first methods))
     (ccase *current-call-mode*
       (:case-1 `(call-method ,(second methods)))
       (:case-2 `(call-method ,(third methods))))))

(This method combination doesn't make any real sense; its only purpose 
is to illustrate my point.)


Background: Obviously, some Common Lisp implementations cache effective 
methods for efficiency reasons, and it would make sense to me that they 
only take static properties into account for this case. However, I am 
not 100% sure.

Any kind of help is appreciated.


Thanks in advance,
Pascal

-- 
Given any rule, however �fundamental� or �necessary� for science, there 
are always circumstances when it is advisable not only to ignore the 
rule, but to adopt its opposite. - Paul Feyerabend

From: Gerd Moellmann
Subject: Re: A method combination can depend on what?
Date: 
Message-ID: <86y98acpck.fsf@gerd.free-bsd.org>
Pascal Costanza <········@web.de> writes:

> Is this correct, or am I missing something?

I have problems understanding you question.  For example, the body of
the define-method-combination in your example, which uses special
variables, is not an effective method but a method combination
function that returns an effective method form.

Is the question perhaps when the method combination function is
called?  If yes, I think AMOP will be of greater help that the CL
standard.  See, for example, the AMOP dictionary entries for
compute-discriminating-function, compute-effective-method,
compute-applicable-methods.
From: Pascal Costanza
Subject: Re: A method combination can depend on what?
Date: 
Message-ID: <aq482u$bfq$1@newsreader2.netcologne.de>
Gerd Moellmann wrote:
> Pascal Costanza <········@web.de> writes:
> 
> 
>>Is this correct, or am I missing something?
> 
> 
> I have problems understanding you question.  For example, the body of
> the define-method-combination in your example, which uses special
> variables, is not an effective method but a method combination
> function that returns an effective method form.

Sorry for not being clear. Yes, the method combination function computes 
the effective method. My question was: What information is the method 
combination function allowed to take into account for computing the 
effective method? As far as I can see, dynamic state like the binding of 
a special variable is excluded.

> Is the question perhaps when the method combination function is
> called?  If yes, I think AMOP will be of greater help that the CL
> standard.  See, for example, the AMOP dictionary entries for
> compute-discriminating-function, compute-effective-method,
> compute-applicable-methods.

Thanks a lot for these hints.


Pascal

-- 
Given any rule, however �fundamental� or �necessary� for science, there 
are always circumstances when it is advisable not only to ignore the 
rule, but to adopt its opposite. - Paul Feyerabend
From: Gerd Moellmann
Subject: Re: A method combination can depend on what?
Date: 
Message-ID: <86vg3ery5e.fsf@gerd.free-bsd.org>
Pascal Costanza <········@web.de> writes:

> My question was: What information is
> the method combination function allowed to take into account for
> computing the effective method?

AFAICT, there's no restriction.  It's up to you.

> As far as I can see, dynamic state like the binding of a special
> variable is excluded.

I guess I'm dense today.  Why do you think that?  Or better, please
tell what you are trying to achieve.
From: Pascal Costanza
Subject: Re: A method combination can depend on what?
Date: 
Message-ID: <3DC66F04.8020803@web.de>
Gerd Moellmann wrote:
> Pascal Costanza <········@web.de> writes:
> 
>>My question was: What information is
>>the method combination function allowed to take into account for
>>computing the effective method?
> 
> AFAICT, there's no restriction.  It's up to you.
> 
>>As far as I can see, dynamic state like the binding of a special
>>variable is excluded.
> 
> I guess I'm dense today.  Why do you think that?  Or better, please
> tell what you are trying to achieve.

Sorry again. You are right - of course, you can reason about special 
variables when computing an effective method in a method combination 
function. However, a change to one of the involved special variables may 
not immediately result in a recomputed effective method because of 
caching. That's what I meant - in general, the computation of effective 
methods should not depend on dynamic properties of the running program. 
(In other words, if the involved special variables are not changed there 
won't be a problem.)

Is this clearer by now? Please see the other postings in this thread by 
Tim Bradshaw and myself.


All the best,
Pascal

-- 
Pascal Costanza               University of Bonn
···············@web.de        Institute of Computer Science III
http://www.pascalcostanza.de  R�merstr. 164, D-53117 Bonn (Germany)
From: Gerd Moellmann
Subject: Re: A method combination can depend on what?
Date: 
Message-ID: <86vg3dbgqj.fsf@gerd.free-bsd.org>
Pascal Costanza <········@web.de> writes:

> However, a change to one of the involved special variables may not
> immediately result in a recomputed effective method because of
> caching. 

That's true.

> That's what I meant - in general, the computation of effective
> methods should not depend on dynamic properties of the running
> program. (In other words, if the involved special variables are not
> changed there won't be a problem.)

I'd write that pretty differently.  But, whatever.
From: Tim Bradshaw
Subject: Re: A method combination can depend on what?
Date: 
Message-ID: <ey3n0op8tau.fsf@cley.com>
* Pascal Costanza wrote:
> Sorry for not being clear. Yes, the method combination function
> computes the effective method. My question was: What information is
> the method combination function allowed to take into account for
> computing the effective method? As far as I can see, dynamic state
> like the binding of a special variable is excluded.

I think it's OK - you can do anything. *But* the computation of the
effective method happens at the time effective methods are computed,
and that may not be when you expect - they almost certainly do not get
computed on the fly but rather get computed `when needed' and then
cached, and the time when that computation happens is pretty vague. In
particular, if you change some special which alters how effective
methods are computed, don't expect them to get recomputed, because
there's no magic which makes that happen - nothing is telling the
system that `when needed' includes `when I change the value of *FOO*'
(and unless *FOO* is a symbol macro, it's hard to see how anything
*could* tell the system that).

--tim
From: Pascal Costanza
Subject: Re: A method combination can depend on what?
Date: 
Message-ID: <3DC66CCE.4060107@web.de>
Tim Bradshaw wrote:
 > * Pascal Costanza wrote:
 >
 >> Sorry for not being clear. Yes, the method combination function
 >> computes the effective method. My question was: What information is
 >>  the method combination function allowed to take into account for
 >> computing the effective method? As far as I can see, dynamic state
 >> like the binding of a special variable is excluded.
 >
 > I think it's OK - you can do anything. *But* the computation of the
 > effective method happens at the time effective methods are computed,
 > and that may not be when you expect - they almost certainly do not
 > get computed on the fly but rather get computed `when needed' and
 > then cached, and the time when that computation happens is pretty
 > vague.

As someone else has pointed out to me, a conforming implementation must
recompute an effective method when class or method precedence changes
because of changes to class definitions or addition/removal of methods.
Apart from that, implementations are free to cache effective methods.

For example, MCL provides (clear-clos-caches) and (clear-gf-cache) to
force recomputation of effective methods, but that's not what one wants
in the general case for efficiency reasons.

So thanks for your help - what I was after was a way to have
an effective method recomputed triggered by changes to special
variables, for example. However, I wasn't aware of the consequences. Now 
I know that even if this were possible it wouldn't be what I want 
(again, for efficiency reasons). I have to rethink my design in this regard.


Thanks a lot,
Pascal

-- 
Pascal Costanza               University of Bonn
···············@web.de        Institute of Computer Science III
http://www.pascalcostanza.de  R�merstr. 164, D-53117 Bonn (Germany)