From: Ken Anderson
Subject: Re: Question about defmethod, call-next-method, and declarations
Date: 
Message-ID: <KANDERSO.96Mar23121518@stout.bbn.com>
In article <··············@hawk.eecs.umich.edu> ·····@eecs.umich.edu (Michael Hucka) writes:

  Is it correct to declare the arguments keyword1 and keyword2 as ignored? I.e.,
  
    (defmethod foo ((arg1 some-class) &key (keyword1 'bar) (keyword2 'baz))
      (declare (ignore keyword1 keyword2))
      (call-next-method))
  
  I'm wondering whether that will have the wrong behavior if the next method
  actually does use those arguments.  If they're not declared, of course, the
  compiler will complain about unused arguments.
  
The arguments are not ignored since
 (call-next-method)
is really the same as
 (call-next-method arg1 :keyword1 keyword1 :keyword2 keyword2) 

k
From: Bruno Haible
Subject: Re: Question about defmethod, call-next-method, and declarations
Date: 
Message-ID: <4jhkgq$hka@nz12.rz.uni-karlsruhe.de>
Michael Hucka <·····@eecs.umich.edu> asked:
>
>  Is it correct to declare the arguments keyword1 and keyword2 as ignored? I.e.,
>  
>    (defmethod foo ((arg1 some-class) &key (keyword1 'bar) (keyword2 'baz))
>      (declare (ignore keyword1 keyword2))
>      (call-next-method))
>  
>  I'm wondering whether that will have the wrong behavior if the next method
>  actually does use those arguments.  If they're not declared, of course, the
>  compiler will complain about unused arguments.
 
Ken Anderson <········@stout.bbn.com> wrote:
> The arguments are not ignored since
>  (call-next-method)
> is really the same as
>  (call-next-method arg1 :keyword1 keyword1 :keyword2 keyword2) 

If there was a (setq keyword1 nil keyword2 nil) statement before the
(call-next-method), then the CL spec (dpANS p. 7-75) says that this wouldn't
affect the arguments passed to the next method. Hence the original
arguments are stored behind the scenes, and the method call roughly
looks like this:

     (lambda (hidden-arg1 &rest hidden-rest)
       (flet ((call-next-method ()
                (apply *next-method* hidden-arg1 hidden-rest)))
         (apply (lambda (arg1 &key (keyword1 'bar) (keyword2 'baz))
                  (declare (ignore keyword1 keyword2))
                  ...
                  (call-next-method))
                hidden-arg1 hidden-rest)))

Of course, the compiler will notice that `hidden-arg1' and `arg1' are
never setq'ed and hence use `hidden-arg1' instead of `arg1' in all places.
And it will warn if keyword1 and keyword2 are not explicitly used.


Bruno Haible                                     email: <······@ilog.fr>
Software Engineer                                phone: +33-1-49083585