Congruence of lamda-lists of methods with their generic-function

Pascal Costanza pc at p-cos.net
Sun Feb 9 17:42:25 UTC 2014


On 9 Feb 2014, at 17:57, Pascal J. Bourguignon <pjb at informatimago.com> wrote:

> If you want to allow any kind of keywords for any call to the generic
> function, you can declare it as:
> 
>    (defgeneric foo (a b &key &allow-other-keys))
>    (defmethod foo (a b &key c d &allow-other-keys) (or c d 42))
> 
> or alternatively, if you're concerned only with a single call, you can
> call it as:
> 
>   (foo unknown-object-1 unknown-object-2 :d 3 :allow-other-keys t)

I recommend to be careful with :allow-other-keys t. I recently used it a bit too indiscriminately, and this created some problems. The reason was that I created a few levels of indirection that looked roughly like this:

(defun foo (a b c &rest args &key k1 k2)
  …
  (apply ‘bar … args)
  …)

If you call (foo 1 2 3 :k3 :allow-other-keys t), this can be handy, but keep in mind that the additional keyword parameter is passed down also in &rest args, and this may screw up further processing down the lines.

It was possible to resolve this with a more careful definition of the parameter lists, and the code is now much cleaner.


Pascal

--
Pascal Costanza
The views expressed in this email are my own, and not those of my employer.






More information about the pro mailing list