From alemmens at xs4all.nl Thu Oct 19 11:01:45 2006 From: alemmens at xs4all.nl (Arthur Lemmens) Date: Thu, 19 Oct 2006 13:01:45 +0200 Subject: [rucksack-devel] Re: [rucksack-cvs] removing class instances from index In-Reply-To: <6a3413f30610190330j1185c565r8d0f8b258d609fa2@mail.gmail.com> References: <6a3413f30610190330j1185c565r8d0f8b258d609fa2@mail.gmail.com> Message-ID: [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 From vikram.bhandoh at gmail.com Thu Oct 19 11:41:44 2006 From: vikram.bhandoh at gmail.com (Vikram Bhandoh) Date: Thu, 19 Oct 2006 12:41:44 +0100 Subject: [rucksack-devel] Re: Re: [rucksack-cvs] removing class instances from index In-Reply-To: References: <6a3413f30610190330j1185c565r8d0f8b258d609fa2@mail.gmail.com> Message-ID: <6a3413f30610190441h7a6c0222ua0ac038d417d04e3@mail.gmail.com> 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))))) # 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))) #> 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))) #> NIL T as you can see calling rucksack-map-class still prints the object Cheers Vikram On 10/19/06, Arthur Lemmens 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 From alemmens at xs4all.nl Thu Oct 19 11:53:53 2006 From: alemmens at xs4all.nl (Arthur Lemmens) Date: Thu, 19 Oct 2006 13:53:53 +0200 Subject: [rucksack-devel] Re: Re: [rucksack-cvs] removing class instances from index In-Reply-To: <6a3413f30610190441h7a6c0222ua0ac038d417d04e3@mail.gmail.com> References: <6a3413f30610190330j1185c565r8d0f8b258d609fa2@mail.gmail.com> <6a3413f30610190441h7a6c0222ua0ac038d417d04e3@mail.gmail.com> Message-ID: Vikram Bhandoh wrote: > I think it's the way I'm going about it.. Here is the code I haven't tried to run your code yet, but at first sight it looks good to me. I'll investigate this when I have a bit more time. Arthur From alemmens at xs4all.nl Thu Oct 19 19:11:52 2006 From: alemmens at xs4all.nl (Arthur Lemmens) Date: Thu, 19 Oct 2006 21:11:52 +0200 Subject: [rucksack-devel] Re: Re: [rucksack-cvs] removing class instances from index In-Reply-To: <6a3413f30610190441h7a6c0222ua0ac038d417d04e3@mail.gmail.com> References: <6a3413f30610190330j1185c565r8d0f8b258d609fa2@mail.gmail.com> <6a3413f30610190441h7a6c0222ua0ac038d417d04e3@mail.gmail.com> Message-ID: Vikram Bhandhoh wrote: > I've tried this but it doesn't work for me. OK, I've looked more closely at your code now. The critical point is that Rucksack's standard class and slot indexes map to the *ids* of persistent objects, *not* to the objects themselves. This is normally hidden from you when you use the implicit class and slot indexing provided by Rucksack. But in your case you're explicitly manipulating the indexes, so instead of doing stuff like: > (index-delete (rucksack-class-index rs 'employee) (object-id emp) emp) you should write: (index-delete (rucksack-class-index rs 'employee) (object-id emp) (object-id emp)) Ditto for the slot indexes. Oh, and you're not supposed to keep references to persistent objects outside of a WITH-TRANSACTION. So the following part of your code isn't safe: > (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))) You don't really need this global EMP, because you can always find it within a transaction by iterating across the rucksack roots or by using the indexing mechanisms. Arthur