&allow-other-keys , What does it do? - Common Lisp

Viewed 383

I'm interested in knowing what &allow-other-keys is supposed to do. I'm getting shockingly few references to it and no real definitions when I consult all documentation I can get my hands on. Best I can figure out is that it's effectively an error handling bit of code that you can put after &key to suppress the checking of key arguments when the macro is being called. For reference, this is where I found it:

(defmacro macro-name ((passed-variable
                       &rest open-args
                       &key &allow-other-keys)
                      &body body)
  ...)
2 Answers

&allow-other-keys is well documented: it suppresses Keyword Argument Checking.

In your example, it makes (macro-name (foo :bar 1) ...) an acceptable invocation of macro-name.

Although I think sds's answer is the right one, it's worth perhaps giving an example what is probably the canonical use-case for &allow-other-keys:

(defun open-unsigned-byte (f &rest kws &key &allow-other-keys)
  (apply #'open f :element-type 'unsigned-byte kws))

This function wants to let open have whatever keyword arguments it takes, possibly including non-standard ones, but wants to make sure that the element-type is unsigned-byte, and that all the additional arguments passed to open are keyword arguments. This works because in the case of duplicated keyword arguments (which are legal) the leftmost one wins.

Related