defstruct constructor uses slot-names in lambda list.
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
Triaged
|
Low
|
Unassigned |
Bug Description
Norbert Paul <email address hidden> via lists.sourcefor
Hi,
reading the hyperspec on defstruct I stumbled over what I consider a bug in
sbcl:
When I do
(macroexpand '(defstruct (boa (:constructor make-boa (b o a))) b o a))
in sbcl I get
(PROGN
#<stuff>
;; and
(DEFUN MAKE-BOA (B O A)
(SB-
#
'((:SLOT T . 1) (:SLOT T . 2) (:SLOT T . 3)) B O A))
(LOCALLY (DECLARE (NOTINLINE SB-KERNEL:
'BOA).
Note that it uses the slot symbols b, o, and a as parameters for
make-boa. Doesn't this violate the specification, as the hyperspec says
"The symbols which name the slots must not be used by the implementation
as the names for the lambda variables in the constructor function, since
one or more of those symbols might have been proclaimed special or might
be defined as the name of a constant variable."?
In fact,
(defconstant c 'a-constant)
(defstruct (boo (:constructor make-boo (c))) c)
generates the error
; C names a defined constant, and cannot be used as a local variable.
A solution could be to replace each argument SYM by (make-symbol (symbol-mane SYM)).
I am using SBCL 1.0.52 on Debian Linux.
Regards
Norbert
Changed in sbcl: | |
assignee: | nobody → Nick Levine (ndl) |
Changed in sbcl: | |
assignee: | Nick Levine (ndl) → nobody |
Actually, I'm having second thoughts.
Consider:
(defvar *foo* (list 1 2))
(defun bar ()
(car *foo*))
(defstruct (foo (:constructor make-foo (*foo* &aux (bar (bar)))))
*foo*
bar)
(let ((foo (make-foo (list 'a 'b))))
(list (foo-*foo* foo) (foo-bar foo))) ; => ((A B) A)
It is not clear to me that this is wrong, and that ((A B) 1) would be right. Renaming user-specified arguments strikes me as suspect: the spec talks about implementation not being allowed to do X, but this is the user explicitly specifying something.
Granted, /not/ considering this a bug means that you cannot use a boa-constructor if you name a slot with a symbol also used as a defconstant or defglobal.
Hm.