From: Jong-won Choi
Subject: &allow-other-keys question
Date: 
Message-ID: <34399435.F6C61611@lgsemicon.co.kr>
Hello,

I need to add parameters(keywords) when the generic function is:

(define-generic test (a b &key c))

I wrote following method:
(defmethod test ((a number) b &key c &allow-other-keys d e)
  (list a b c d e))
  
It seems to me this works. Because I'm new using &allow-other-keys, I'd
like to know is this appropriate usage of &allow-other-keys. Or is there
any other good way to add parameters?
I read some references on this - very few and same examples. Could you
let me know other good usage of &allow-other-keys than CLtL2 example
also?

Thanks,

- Jong-won Choi

From: Barry Margolin
Subject: Re: &allow-other-keys question
Date: 
Message-ID: <61chpd$fii@pasilla.bbnplanet.com>
In article <·················@lgsemicon.co.kr>,
Jong-won Choi  <······@lgsemicon.co.kr> wrote:
>I need to add parameters(keywords) when the generic function is:
>
>(define-generic test (a b &key c))

Shouldn't this be DEFGENERIC?

>I wrote following method:
>(defmethod test ((a number) b &key c &allow-other-keys d e)
>  (list a b c d e))
>  
>It seems to me this works. Because I'm new using &allow-other-keys, I'd
>like to know is this appropriate usage of &allow-other-keys. Or is there
>any other good way to add parameters?

I think you're misunderstanding what &allow-other-keys does.  It doesn't
require argument names after it -- it means that the function or method
accepts keywords *in addition to* the ones specified in its lambda list.
In your case, you just want to be able to accept additional keywords :D and
:E, so you don't need &allow-other-keys.  You should use:

(defmethod test ((a number) b &key c d e) ...)

This is explicitly addressed in CLtL2, section 28.1.6.4 on Congruent
Lambda-Lists, which says: "Each method can accept additional keyword
arguments of its own."  P.793 has examples of this.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.
From: Jong-won Choi
Subject: Re: &allow-other-keys question
Date: 
Message-ID: <3439DD9C.B7C6DBAA@lgsemicon.co.kr>
Barry Margolin wrote:
> 
> <SNIP>
> >(define-generic test (a b &key c))
> 
> Shouldn't this be DEFGENERIC?

I'm sorry. There were typos.

> >I wrote following method:
> >(defmethod test ((a number) b &key c &allow-other-keys d e)
> >  (list a b c d e))
> >
> >It seems to me this works. Because I'm new using &allow-other-keys, I'd
> >like to know is this appropriate usage of &allow-other-keys. Or is there
> >any other good way to add parameters?
> 
> I think you're misunderstanding what &allow-other-keys does.  It doesn't
> require argument names after it -- it means that the function or method
> accepts keywords *in addition to* the ones specified in its lambda list.

Understood. Thanks for your explaination.

> In your case, you just want to be able to accept additional keywords :D and
> :E, so you don't need &allow-other-keys.  You should use:
> 
> (defmethod test ((a number) b &key c d e) ...)

Then here is my correction:

*Assume I have no source codes & someone wrote:
(defgeneric test (a &key b &allow-other-keys) ...)
(defmethod test ((a number) &key b &allow-other-keys) ...)

I want to add additional task like:
(defmethod test :around ((a number) &key b my-key1)
  (list my-key1 (call-next-method)))

> This is explicitly addressed in CLtL2, section 28.1.6.4 on Congruent
> Lambda-Lists, which says: "Each method can accept additional keyword
> arguments of its own."  P.793 has examples of this.

I'm going to read this again with your hint.

I was confused normal functions(which have &allow-other-keys) with
generic functions/methods (which have &allow-other-keys). My summary:

With &rest, one can access additional keys in a function:
(defun example1 (a &rest z &key b &allow-other-keys)...)
Without &rest, following example just ignores additional keys, right?
(defun example2 (a &key b &allow-other-keys)...) 
In CLOS, when &allow-other-keys(without &rest) is in lambda list of
generic function/methods, any keyword args can be used and (typically)
the additional args will be used in a method.

Thank you,

- Jong-won Choi