[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
AKCL BUG(?) Defstruct :include with :type vector or list inserts extra slot
This is at least a bug in spirit, if not letter.
The basic problem is that if you use defstruct to define accessors and
selectors for the initial slots of a vector or list, and you use the
:include option on defstruct to define further accessors for later
slots, the accessors defined will skip a slot! This is contrary to what
you might expect. I think the problem is someone is also including a
slot for the name (normally slot 0).
For example:
------------------------------------------------------------------------
(defstruct (test-struct (:type vector)
:named
:conc-name
(:constructor nil))
first second third)
(defstruct (test-struct2 (:type vector)
:named
(:include test-struct)
:conc-name
(:constructor nil))
fourth fifth sixth)
(defvar *named-test-vector*
(vector 'test 1 2 3 4 5 6 7 8))
------------------------------------------------------------------------
I think it is reasonable to expect that test-struct2-fourth should
access the slot immediately following the slot accessed by
test-struct-third. CLtL doesn't specifically say this should be so,
but it seems to be in the spirit. However, we find that this is not the
case in AKCL (note there also seems to be a bug in where dribble puts
end of line):
------------------------------------------------------------------------
>
(compile-file "test-include-vector")Compiling test-include-vector.lsp.
End of Pass 1.
End of Pass 2.
OPTIMIZE levels: Safety=0 (No runtime error checking), Space=0, Speed=3
Finished compiling test-include-vector.lsp.
#"test-include-vector.o"
>
(load "test-include-vector")Loading test-include-vector.o
Finished loading test-include-vector.o
2504
>
(test-struct-first *named-test-vector*)1
>
(test-struct-second *named-test-vector*)2
>
(test-struct-third *named-test-vector*)3
>(test-struct2-fourth *named-test-vector*)5
>
(test-struct2-fifth *named-test-vector*)6
>
------------------------------------------------------------------------
The same thing happens on structures of type list.
The result is there doesn't seem to be a way of cleanly using defstruct
to define a hierarchy of accessors for vectors like that above.
Symbolics Common Lisp does work as expected.
A partial workaround requires using #. (read time eval), but of course
this won't relate this new struct to the old one (e.g. make a
complete constructor, or relate them in the type hierarchy).
------------------------------------------------------------------------
(defstruct (test-struct3 (:type vector)
:named
(:initial-offset #.(1- (length (make-test-struct))))
:conc-name)
fourth fifth sixth)
------------------------------------------------------------------------
CarlManning@ai.mit.edu