[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: call-next-method



> Is it really correct if a compiler warns in the following code
> 
> (defclass test ()
>   ()
>   )
> 
> (defmethod testmethod ((ich test) foo)
>   (print foo))
> 
> (defclass test-1 (test)
>   ())
> 
> (defmethod testmethod ((ich test-1) foo)
>   (call-next-method))
> 
> (testmethod (make-instance 'test-1) 4)
> 
> with 
> ;Compiler warnings :
> ;   Unused lexical variable Foo, in Testmethod.
> 
> since foo is actually used in testmethod ((ich test) foo)
> because of the call-next-method?

Yes, this is correct behavior.  The call-next-method does not refer to the 
parameter foo, it (conceptually) gets the value that foo is bound to from some 
other place.  Recall that modifying the value of foo (by setq within the method 
body) does not change the set of values that are passed along by 
(call-next-method).

> My problem is that Macintosh Common Lisp 2.0 warns but
> Allegro Cl/PC 1.0 does not and I have to exchange code
> between the two platforms. Even worse, if I change
>  testmethod ((ich test-1) foo) to
> 
> (defmethod testmethod ((ich test-1) foo)
>   (declare (ignore foo))
>   (call-next-method))
> 
> Macintosh Common Lisp 2.0 is satisfied but Allegro Cl/PC 1.0
> complains that foo is actually used and not ignored, so I have to write
> 
> (defmethod testmethod ((ich test-1) foo)
>   #+:ccl-2 (declare (ignore foo))
>   (call-next-method))
> 
> what is quite annoying, since this code is really not platform-dependent

I'd call this a bug in Allegro CL/PC 1.0, and would change that #+ccl-2 to be a 
#-<feature for allegro cl/pc 1.0>.