defstruct constructor uses slot-names in lambda list.

Bug #984813 reported by Nikodemus Siivola on 2012-04-18
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

Norbert Paul <email address hidden> via to sbcl-bugs


reading the hyperspec on defstruct I stumbled over what I consider a bug in

When I do
  (macroexpand '(defstruct (boa (:constructor make-boa (b o a))) b o a))
in sbcl I get
   ;; and
      '((:SLOT T . 1) (:SLOT T . 2) (:SLOT T . 3)) B O A))

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.


Nikodemus Siivola (nikodemus) wrote :

Actually, I'm having second thoughts.


(defvar *foo* (list 1 2))

(defun bar ()
  (car *foo*))

(defstruct (foo (:constructor make-foo (*foo* &aux (bar (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.


tags: added: defstruct
Nick Levine (ndl) on 2013-04-16
Changed in sbcl:
assignee: nobody → Nick Levine (ndl)
Nick Levine (ndl) on 2013-04-16
Changed in sbcl:
assignee: Nick Levine (ndl) → nobody
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers