This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Passing &key arguments through to lower levels

3 posts · 2020 views

I want to extend adjoin, but want to maintain it full flexibility. So somehow I need to pass any keyword arguments that come in through to a call to adjoin I make in my version:
(defun my-adjoin (item list &key key test test-not)
     (do-something 
            (adjoin item list WHAT-DO-I-PUT-HERE?)))
Or is this putting me into macro territory?

Last edited by ramarren on , edited 1 time in total. Reason: Added code tags

Re: Passing &key arguments through to lower levels

Please use code tags for posting code samples in the future.

Keyword arguments always have a default value, which, if not specified in the argument list, is NIL, which means you can just call ADJOIN with all the arguments.
(defun my-adjoin (item list &key key test test-not)
  (do-something
      (adjoin item list :key key :test test :test-not test-not)))
If you want to avoid typing you can do something like:
(defun my-adjoin (item list &rest key-args &key key test test-not)
  (do-something
      (apply #'adjoin item list key-args)))
Common Lisp allows both &rest and &key argument specification. In this particular case the &key would only serve as documentation anyway. But it complicates the interface, and in such cases I usually would prefer to write out the keyword arguments explicitly.

Re: Passing &key arguments through to lower levels

Thank you. I will remember the code tags in the future.