Subject: Re: help w/ &key in macros
From: Erik Naggum <cl@naggum.no>
Date: 1998/05/31
Newsgroups: comp.lang.lisp
Message-ID: <3105643949024871@naggum.no>


* David Bakhash
| Basically, what I think might be happening is that if I define a
| function like:
| 
| (defun f (x &optional y &key k1 k2)
|   (..))
| 
| and then call it like this:
| 
| (f 10 :k1 3 :k2 4)
| 
| then the &optional argument `y' gets the keyword value `:k1', and I
| somehow don't agree that this is how it should be, though I can also
| see how this is a subtle point, where someone had to make a decision.

  you cannot disallow passing the keyword :K1 to the optional argument Y
  via the standard argument-parsing machinery, which also cannot force the
  argument list to match keywords at particular positions, such as ending
  in a keyword plist.  for the whole story on the ordinary lambda list:
  http://www.harlequin.com/education/books/HyperSpec/Body/sec_3-4-1.html

| So, the question is how do be able to pass the args the way I did,
| such that it still works.

  taking the easy way out and disallowing keywords as values of optional
  arguments, which is not a brilliant solution, this could be a start.

(defun f (x &rest .arguments.)
  (declare (dynamic-extent .arguments.))
  (let ((y (unless (keywordp (first .arguments.)) (pop .arguments.))))
    (destructuring-bind (&key k1 k2) .arguments.
      ...)))

  this is obviously a macro-expansion...  it is also not tested.

#:Erik
-- 
  "Where do you want to go to jail today?"
			-- U.S. Department of Justice Windows 98 slogan