From: Pascal Costanza on
On 13/06/2010 20:24, Paul Griffioen wrote:
>
> Why do compilers warn about unused keyword in methods when (call-next-
> method) is used? For example when compiling
>
> (defclass some-class () ())
>
> (defmethod foo ((object some-class) some-arg&key some-key)
> (call-next-method))
>
> SBCL and LispWorks warn about keyword some-key (haven't tried other
> compilers). The keyword is passed to the next method so declaring it as
> unused seems wrong. And they don't warn about argument some-arg.
>
> Is there any reason for this? And is there a way to get rid of these
> warnings?

If there is no need to use the keyword argument in the method body, it's
better to just omit it. You can just say this:

(defmethod foo ((object some-class) some-arg &key)
...)

This doesn't work if the defgeneric form also mentions the particular
keyword argument in question, but maybe it shouldn't either, since it
doesn't seem to be necessary for all methods.

The exact rules when you have to mention a keyword argument and when not
are in the HyperSpec in Section 7.6.5. Note that keyword arguments
require extra processing, so not mentioning them may be preferable. If
all else fails, (declare (ignore some-key)) always does the trick.


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/