From: Pascal Costanza on 14 Jun 2010 08:02 On 14/06/2010 01:27, Paul Griffioen wrote: > On Mon, 14 Jun 2010 00:41:51 +0200, Pascal Costanza wrote: > >> 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 > > Thanks for the explanation and the reference. I didn't know these rules. > > In my case the keyword is mentioned in the generic function so I have to > mention it in the method. I'm not sure if I want to remove the keywords > in the generic function. Why do you say that the keyword doesn't seem > necessary? I want the method to accept it but the default handling is > sufficient. In that case it's ok to have it in the defgeneric form. > I was uncertain about an ignore declaration (or the ignorable that > Raffael Cavallaro mentions) because the regular argument doesn't need it. > Is such a declaration always valid? Because the keyword is used, although > not visible. The declaration seems a bit strange when I read the code, > but maybe I just have to get used to it. You just have to get used to it. ;) 'ignore is good when you know you don't want to use the variable. If you then happen to use it anyway, you will get a warning, which may be helpful. 'ignorable is good when you don't care. I think this case occurs rarer than 'ignore in manually written code, but can be very useful in macros that generate function or method definitions. 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/
|
Pages: 1 Prev: does clisp have a profiler (like sbcl)? Next: what is the purpose of (coerce ... 'function) |