From: Marcin Tustin
Subject: defmethod
Date: 
Message-ID: <FxY07.3434$Tv5.530252@news6-win.server.ntlworld.com>
    Ok, this is probably a stupid question, but how do I write methods with
differing numbers of arguments, like so:
(defmethod foo ((this moomin) qux bar) ())
(defmethod foo ((this moomin) qux bax quzz) ())

Using CLISP, and it's giving me errors about numbers of arguments.
Cheers.

From: Kent M Pitman
Subject: Re: defmethod
Date: 
Message-ID: <sfw4rsrtv0x.fsf@world.std.com>
"Marcin Tustin" <···@bar.com> writes:

>     Ok, this is probably a stupid question, but how do I write methods with
> differing numbers of arguments, like so:
> (defmethod foo ((this moomin) qux bar) ())
> (defmethod foo ((this moomin) qux bax quzz) ())

The strict answer to your question as worded is: You can't.
Methods must be "congruent" (have the same argument signature).

However, you can have optional arguments.

 (defmethod foo ((this moomin) qux bar &optional baz) ())

On the other hand, it is probably not what you SHOULD do if you feel
compelled to pass a BAR in the 3 argument case for argument 3, but a
BAX in the four-argument case for argument 3.   That's not "generic",
it's "overloading" (using the same function for two unrelated purposes).

CL thinks when you have unrelated purposes you should use unrelated generics.

> Using CLISP, and it's giving me errors about numbers of arguments.

Glad to hear it's conforming to the spec. ;-)

Btw, you should read the section on method congruency, if not the whole
chapter on CLOS, in the CL HyperSpec.
From: Jason Kantz
Subject: Re: defmethod
Date: 
Message-ID: <92f4a69d.0107060657.7457f1dd@posting.google.com>
you could try ...

(defmethod foo ((this t) &key qux bar &allow-other-keys))
(defmethod foo ((this t) &key qux bax quzz &allow-other-keys))
From: Kent M Pitman
Subject: Re: defmethod
Date: 
Message-ID: <sfwae2iaux2.fsf@world.std.com>
········@yahoo.com (Jason Kantz) writes:

> 
> you could try ...
> 
> (defmethod foo ((this t) &key qux bar &allow-other-keys))
> (defmethod foo ((this t) &key qux bax quzz &allow-other-keys))

But it wouldn't work.  method dispatch does not check which keys are
supplied as part of discerning which method to use.

Read the hyperspec (section 7.6, and especially 7.6.4)
on how this really works.
From: Jason Kantz
Subject: Re: defmethod
Date: 
Message-ID: <92f4a69d.0107090446.79275aa8@posting.google.com>
> > (defmethod foo ((this t) &key qux bar &allow-other-keys))
> > (defmethod foo ((this t) &key qux bax quzz &allow-other-keys))

This was a mistake.  What I meant to point out was that keyword
arguments are usefull for creating methods that might need their own
parameters to tweak some particular behavior:

(defmethod foo ((this t) &key qux bar) ...)
(defmethod foo ((this moomin) &key qux bax quzz) ...)