[rucksack-devel] Re: Re: [rucksack-cvs] removing class instances from index

Vikram Bhandoh vikram.bhandoh at gmail.com
Thu Oct 19 11:41:44 UTC 2006


Thanks for the prompt reply.
I've tried this but it doesn't work for me.
I think it's the way I'm going about it.. Here is the code

here is the code

(eval-when (:compile-toplevel :load-toplevel :execute)

  (defparameter *hacker-rucksack* #p"/tmp/rucksack/hackers/")

  (with-rucksack (rs *hacker-rucksack* :if-exists :supersede)
    (with-transaction ()

      (defclass employee ()
	((person :initarg :person :reader person
		 :index :case-insensitive-string-index)
	 (history :initarg :history :accessor history)
	 (salary :initarg :salary :accessor salary :index :number-index)
	 (job :initarg :job :accessor job :index :symbol-index))
	(:metaclass persistent-class)
	(:index t)))))
#<PERSISTENT-CLASS EMPLOYEE>
T

(defvar emp nil)

(with-rucksack (rs *hacker-rucksack*)
  (with-transaction ()
    (setf emp (make-instance 'employee :person "vb" :salary 100 :job
'monkey :rucksack rs))
    (add-rucksack-root emp rs)))
T
T

(with-rucksack (rs *hacker-rucksack*)
  (with-transaction ()
    (rucksack-map-class rs 'employee #'print)))

#<EMPLOYEE #40 in #<STANDARD-CACHE of size 10000, heap
#P"/tmp/rucksack/hackers/heap" and 16 objects in memory.>> NIL
T


(with-rucksack (rs *hacker-rucksack*)
  (with-transaction ()
    (index-delete (rucksack-class-index rs 'employee) (object-id emp) emp)
    (index-delete (rucksack-slot-index rs 'employee 'person) (person emp) emp)
    (index-delete (rucksack-slot-index rs 'employee 'salary) (salary emp) emp)
    (index-delete (rucksack-slot-index rs 'employee 'job) (job emp) emp)
    (rucksack::delete-rucksack-root emp rs)
    (setf emp nil)))
NIL
T

(with-rucksack (rs *hacker-rucksack*)
  (with-transaction ()
    (rucksack-map-class rs 'employee #'print)))

#<EMPLOYEE #40 in #<STANDARD-CACHE of size 10000, heap
#P"/tmp/rucksack/hackers/heap" and 16 objects in memory.>> NIL
T

as you can see calling rucksack-map-class still prints the object

Cheers
Vikram

On 10/19/06, Arthur Lemmens <alemmens at xs4all.nl> wrote:
> [Moving this from the rucksack-cvs list to rucksack-devel]
>
> Vikram Bhandoh wrote:
>
> > how do I delete an instance from rucksack so that when I run
> > rucksack-map-slot I don't see that specific instance again?
>
> There is not one single function to delete an instance from a
> rucksack (just like there is no such function in 'normal' Lisp).
> So if you want to be sure that you'll never 'see a specific
> instance again', you must make sure that there no other persistent
> references to that instance.
>
> If the only persistent references to an instance are via Rucksack's
> slot or class indexes, deleting the object from those indexes should
> do what you want.
>
> > (defclass employee ()
> >       ((person :initarg :index-on :reader person
> >                       :index :case-insensitive-string-index)
> >        (history :initarg :history :accessor history)
> >        (salary :initarg :object-pos :accessor object-pos :index :number-index)
> >        (job :initarg :job :accessor job :index :symbol-index))
> >       (:metaclass persistent-class)
> >       (:index t))
>
> It looks like you have one class index (because of (:INDEX T)) and three
> slot indexes (for PERSON, SALARY and JOB) here, right?  If you want to
> get rid of an employee instance you'll have to remove it from all four
> indexes.
>
> (Maybe it would be a good idea to add some function to Rucksack to
> automatically remove an instance from all indexes.  But at the moment
> you'll have to do this by hand.)
>
> > Any help will be greatly appreciated.
>
> Did this help?
>
> Arthur
>
>


-- 
"Don't worry about what anybody else is going to do. The best way to
predict the future is to invent it." - Alan Kay



More information about the rucksack-devel mailing list