[bknr-devel] bknr.indices, the slot NIL is missing from the object

Hans Hübner hans at huebner.org
Thu Feb 21 06:26:02 UTC 2008


Hi Klaus,

the class-index needs to know a slot that it uses for indexing the
objects.  This slot is the unique ID that the index works on.  It must
be added to your base class, but as you can see in the corrected
example below, that should not be much of a problem.

Note that the :INDICES option in an INDEXED-CLASS either accepts a
predefined index or initargs to create a fresh index.  It is confusing
to mix both initargs and the :INDEX option (which specifies the
preexisting index *CLASS-INDEX* to be used).  I added code to detect
this case.  More error checking would certainly be helpful, so please
report problems when you encounter them and I'll try to make the code
generate better diagnostics.

Please let us know if you have further questions.

Hans

(in-package :bknr.indices)

(defvar *class-index*  (index-create 'class-index :index-subclasses t
:slot-name 'id))
(defvar *object-id* 0)

(defclass base-object ()
 ((id :initform (incf *object-id*)))
 (:metaclass indexed-class)
 (:class-indices (class :index *class-index*
                        :index-reader objects-of-class
                        :index-values all-objects
                        :index-subclasses t
                        :index-keys all-class-names)
                 (classes :index-type class-index
                          :index-initargs (:index-superclasses t)
                          :slots (id)
                          :index-subclasses t
                          :index-reader objects-with-class)))

(defclass child1 (base-object)
 ()
 (:metaclass indexed-class))

(defclass child2 (base-object)
 ((a :initarg :a))
 (:metaclass indexed-class))

(defmacro with-tracing (&rest forms)
  `(progn ,@(mapcar (lambda (form) `(format *trace-output* "~A =>
~A~%" (quote ,form) ,form)) forms)))

(with-tracing
 (make-instance 'child1)
 (all-objects)
 (destroy-object (first (all-objects)))

 (make-instance 'child1)
 (make-instance 'child2)
 (make-instance 'child1)
 (all-class-names)
 (all-objects)
 (objects-with-class 'child1)
 (objects-with-class 'child2))

2008/2/21, Klaus Unger <UngerKlaus at gmx.de>:
> Hi,
>
>  when using class indices they do not have a slot name. On
>  destruction/index-remove this throws a condition on checking slot-boundp.
>
>  I am using SBCL 1.0.14.23 and the latest bknr indices code, only indices,
>  nothing else.
>
>  Best regards
>   Klaus
>
>  ;Package changed to BKNR.INDICES
>  #<PACKAGE "BKNR.INDICES">
>
>  BKNR.INDICES>
>  (defvar *class-index* (index-create 'class-index :index-subclasses t))
>
>  *CLASS-INDEX*
>
>  BKNR.INDICES>
>  (defclass base-object ()
>   ()
>   (:metaclass indexed-class)
>   (:class-indices (class :index *class-index*
>     :slots nil
>     :index-reader objects-of-class
>     :index-values all-objects
>     :index-subclasses t
>     :index-keys all-class-names)
>   (classes :index-type class-index
>     :index-initargs (:index-superclasses t)
>     :slots nil
>     :index-subclasses t
>     :index-reader objects-with-class)))
>
>  #<INDEXED-CLASS BASE-OBJECT>
>  ; in: LAMBDA NIL
>  ;     (SB-KERNEL:FLOAT-WAIT)
>  ;
>  ; note: deleting unreachable code
>  ;
>  ; compilation unit finished
>  ;   printed 1 note
>
>  BKNR.INDICES>
>  (defclass child1 (base-object)
>   ()
>   (:metaclass indexed-class))
>
>  #<INDEXED-CLASS CHILD1>
>
>  BKNR.INDICES>
>  (defclass child2 (base-object)
>   ((a :initarg :a))
>   (:metaclass indexed-class))
>
>  #<INDEXED-CLASS CHILD2>
>
>  BKNR.INDICES>
>  (make-instance 'child1)
>
>  #<CHILD1 {AC66381}>
>
>  BKNR.INDICES>
>  (all-objects)
>
>  (#<CHILD1 {AC66381}>)
>
>  BKNR.INDICES>
>  (destroy-object (first (all-objects)))
>
>  When attempting to test to see whether slot is bound (SLOT-BOUNDP),
>  the slot NIL is missing from the object #<CHILD1 {A7422D9}>.
>    [Condition of type SIMPLE-ERROR]
>         0: [ABORT] Return to SLIME's top level.
>         1: [TERMINATE-THREAD] Terminate this thread (#<THREAD "repl-thread"
>  {B54A251}>)
>  ]> Quit debug
>  _______________________________________________
>  bknr-devel mailing list
>  bknr-devel at common-lisp.net
>  http://common-lisp.net/cgi-bin/mailman/listinfo/bknr-devel
>



More information about the Bknr-devel mailing list