Subject: [clisp-list] DEFSTRUCT/:CONC-NAME and accessor name collisions

From: Christophe Rhodes <[email-masked]>
Date: Wed Oct 22 08:04:17 2003

Hi,

I think this is a bug in Clisp 2.31:

--- foo.lisp ---
  (defstruct foo a b)
  (defstruct (bar (:include foo) (:conc-name foo-)) c)
  (defun quux (x) (foo-a x))
  (defun frobozz (x y) (setf (foo-a x) y))
--- foo.lisp ---

The transcript below shows the problem: essentially, while the reader
used in QUUX is respecting the constraint on colliding names for slot
accessors (see the page for DEFSTRUCT, in the :CONC-NAME section), the
writer in FROBOZZ isn't.

  csr21@mu:~$ clisp -ansi -q
  
  [1]> (lisp-implementation-version)
  "2.31 (released 2003-09-01) (built 3273208247) (memory 3275808511)"
  [2]> (compile-file "/tmp/foo.lisp")
  
  Compiling file /tmp/foo.lisp ...
  
  Wrote file /tmp/foo.fas
  0 errors, 0 warnings
  #P"/tmp/foo.fas" ;
  NIL ;
  NIL
  [3]> (load *)
  ;; Loading file /tmp/foo.fas ...
  ;; Loaded file /tmp/foo.fas
  T
  [4]> (quux (make-foo)) ; as expected
  NIL
  [5]> (frobozz (make-foo) t) ; not as expected
  
  *** - SYSTEM::%STRUCTURE-STORE: #S(FOO :A NIL :B NIL) is not a structure of type BAR
  
Disassembly of QUUX and FROBOZZ respectively show that the expected
types are FOO and BAR, respectively.

I hope that's enough information; let me know if you need any more
details.

Cheers,

Christophe
-- 
http://www-jcsu.jesus.cam.ac.uk/~csr21/       +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%")    (pprint #36rJesusCollegeCambridge)

---

From: Sam Steingold <[email-masked]>
Date: Wed Oct 22 10:33:04 2003

> * Christophe Rhodes <[email-masked]> [2003-10-22 13:32:53 +0100]:
>

<http://clisp.cons.org/impnotes/structures.html>:

  The :INHERIT option is exactly like :INCLUDE except that it does not
  create new accessors for the inherited slots (this is a CLISP
  extension).

If you replace :INCLUDE with :INHERIT in your code, it will work.

I wonder if making DEFSTRUCT smarter and not redefining accessors when
not needed is the better way and should be used instead of :INHERIT.

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Daddy, what does "format disk c: complete" mean?

---

From: Christophe Rhodes <[email-masked]>
Date: Wed Oct 22 13:33:10 2003

Sam Steingold <[email-masked]> writes:

> did you send the patch as an attachment?

Yep.  OK.

> could you please just append it and re-send the message?

See below (the point being that the DEFSETF that it expands to does
REMPROP inside EVAL-WHEN, so this has to too).

Cheers,

Christophe

--- /home/csr21/misc-cvs/clisp/src/defstruct.lisp	2003-02-15 17:57:35.000000000 +0000
+++ defstruct.lisp	2003-10-22 15:03:23.000000000 +0100
@@ -326,8 +324,9 @@
                        (if (consp type)
                          `(LIST 'SETF (LIST 'AREF STRUCT ,offset) VALUE)
                          `(LIST 'SETF (LIST 'SVREF STRUCT ,offset) VALUE)))))
+		(eval-when (compile eval load)
                 (SYSTEM::%PUT ',accessorname 'SYSTEM::DEFSTRUCT-WRITER
-                              ',name))))))
+                              ',name)))))))
     slotlist))
 
 ;; Two hooks for CLOS