[Openmcl-devel] Warning about unused arguments in generic function methods

Gary Byers gb at clozure.com
Wed Nov 14 09:27:11 UTC 2007


For a parameter specialized (implicitly or explicitly) to the
T class, it might be the case that that parameter is strictly
used for discrimination, but it's at least equally likely that
it's "just an argument".  For example:

(defmethod stream-write-char ((s telnet-stream) char)
   s)

I think that I would want a warning telling me that I'd forgotten
to reference CHAR; if I hadn't referenced S either ... well, it's
at least somewhat plausible that the specialized parameter was
used for discrimination only (though I think that I'd like to
know if I wrote a STREAM-WRITE-CHAR method that didn't reference
either of its arguments.)

[If I actually -wanted- to ignore the character - as in

(defmethod stream-write-char ((s null-stream) char)
   (declare (ignore char)))

the IGNORE declaration doesn't seem too painful and seems to make the
intentional ignoring of the argument clear]

It's certainly possible to think of examples where the failure to
reference a parameter that's specialized to the T class is in no way
anomalous (likely because such parameters were used solely for
discrimination.)  I can't think of a way for the compiler to guess
that when compiling a method body (or at least no way for it to guess
right consistently): that depends on contracts and conventions and (to
some extent at least) on coding style.

It's not clear that method qualifiers change this significantly,
but I do wonder about cases like:

(defmethod stream-write-char ((s some-stream-class) c)
   (call-next-method))

since the 0-arg CALL-NEXT-METHOD arguably references the explicit
arguments.

DEFMETHOD could macroexpand into something which declares all
required method arguments to be IGNORABLE (it currently does
that only for those things that're specialized to something
other than the T class), perhaps under the control of some
global variable (*DEFMETHOD-DECLARE-ALL-SPECIALIZED-ARGUMENTS-IGNORABLE*
or some such.)  I don't know how you'd know how to set that so
that you got warnings in cases like the STREAM-WRITE-CHAR but
not in the cases that you find annoying.


On Wed, 14 Nov 2007, Hans Hübner wrote:

> Hi,
>
> is there a way to make OpenMCL stop complaining about unused arguments
> in generic function methods?  I am fine with the warning in standard
> function definitions, but with methods it makes less sense because
> often, the arguments are present just to match the generic function
> signature and rightfully ignored.  This is especially true with
> :before and :after methods, where I find it very annoying to have to
> explicitly ignore unused arguments
>
> -Hans
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>


More information about the Openmcl-devel mailing list