[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
BOA constructor questions
- To: Guy Steele <gls@THINK-AQUINAS.ARPA>, LOOSEMORE@UTAH-20.ARPA
- Subject: BOA constructor questions
- From: David A. Moon <Moon@SCRC-STONY-BROOK.ARPA>
- Date: Sat, 28 Dec 85 18:02 EST
- Cc: common-lisp@SU-AI.ARPA
- In-reply-to: <851226160949.7.GLS@THINK-JEHOSEPHAT.ARPA>
Date: Thu, 26 Dec 85 16:09 EST
From: Guy Steele <gls@THINK-AQUINAS.ARPA>
Date: Thu 26 Dec 85 13:38:50-MST
From: SANDRA <LOOSEMORE@UTAH-20.ARPA>
It is not clear from the discussion of BOA constructors in the manual what
is supposed to happen if you don't mention all the slot names in the arglist,
or even that it's legal to omit slots from the arglist. Presumably, the
omitted slots should be initialized to whatever default value was given in
the body of the defstruct; if this is the case, the manual should say so.
Perhaps a better example would help.
I agree with your interpretation and with the suggestion for improving the manual.
Also, it says that "the keywords &optional, &rest, and &aux are recognized
in the argument list". Is there a reason why &key is not permitted? Or
is this an oversight?
I don't see any technical reason why &KEY should not be permitted, with
semantics analogous to those for &OPTIONAL.
Indeed. It works with the obvious semantics in our implementation.
Then the standard
constructor function can be explained as a special case the more general
constructor feature that happens to take an argument for every slot and
takes them all as &KEY arguments.
But this prompts in me another question: does
(defstruct (foo (:constructor build-foo (&optional baz &aux baz)))
(make-foo) initializes BAZ to 5
(make-foo :baz 43) initializes BAZ to 43
(build-foo 91) initializes BAZ to 91
(build-foo) *does not initialize* BAZ ?
If not, how else can I say it? (Never mind why I would want to.)
Isn't this in conflict with your (Guy's) suggested clarification to page 60,
that a function may not have two parameters with the same name? If that clarification
was not intended to apply to &AUX variables, you didn't say so.
The way I read the Common Lisp manual, your example defstruct above does not
define any function named make-foo. You'd have to say
(defstruct (foo (:constructor build-foo (&optional baz &aux baz))
if you wanted that.
I think the answer to "how else can I say it?" is that you can't say
it except by being more explicit and verbose, e.g.
(defstruct (foo (:constructor build-foo (&optional baz))
(:constructor make-foo (&key (baz 5))))