[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

&key in defstruct :constructor arglists



Is there a really good reason why the arglists for :constructor functions
may *not* include a mix of keyword and non-keyword specifiers??
 CLtL, page 316:
    "In addition, the keywords &optional, &rest, and &aux are recognised
     in the argument list. They work in the way you might expect ..."

I would like to do this:
(defstruct (foo (:constructor create-foo (a &optional b (c 'sea)
					    &key (d 2)
					    &aux e (f 'eff))))
  (a 1) (b 2) (c 3) (d 4) (e 5) (f 6))


But CLtL encourages me do something ugly like this:
(defstruct (foo (:constructor create-foo% (a b c d &aux e (f 'eff))))
  (a 1) (b 2) (c 3) (d 4) (e 5) (f 6))

(defun create-foo (a &optional b (c 'sea) &key (d 2))
  (create-foo% a b c d))

Even so, the handling of foo-b is incorrect if create-foo is called with
only 1 argument.  Must a user hand code all the supplied-p forms to do this?
  CLtL: "The actions taken in the B and E cases were carefully chosen to
         allow the user to specify all possible behaviors."
The intent is clearly to make this *easier* for programmers...

Is the code to handle &key really any different than for &optional?

  Biggest impact i can see here is that we might lose the cuteness of
strictly "By Order of Arguments" --> "BOA-constructor".



PS to: cl-cleanup-request@sail.stanford.edu
  please add me to this list: peck@sun.com