[rucksack-devel] inherited slots

Cyrus Harmon ch-rucksack at bobobeach.com
Wed Nov 29 18:56:25 UTC 2006


On Nov 29, 2006, at 12:06 AM, Cyrus Harmon wrote:
> On Nov 28, 2006, at 11:55 PM, Cyrus Harmon wrote:
>> Hmm... okay. The obvious motivation for this is that one could  
>> subclass an existing class with a rucksack metaclass and get a  
>> persistent version of existing data. I can see how this might give  
>> folks the heebie-jeebies, but it would be nice to better  
>> understand what's _wrong_ with this approach. As an alternative,  
>> perhaps a defclass option for inherited slots that _should_ be  
>> persistent would be nice, as opposed to having redefine every slot  
>> that should be persistent.
>
> You know, like maybe a :persistent-slots option to the class  
> definition. Oh, what's that you say, that's already there? Great,  
> I'll try that. Thanks!

Ok, obviously that was wrong... So I guess the questions are:

1) How can I make inherited slots (from non-persistent classes)  
persistent? It seems that the answer is that I can just list them in  
the slot definitions for the persistent class and that they will pick  
up the appropriate slot definition arguments, or whatever they are  
called (:initarg, :initform, etc...) from the parent class.

2) What happens to non-persistent slots (in this case of parent  
classes) when an object is serialized form disk? If I try the  
following (adapted from the rucksack-test file):


(cl:defpackage :rucksack-object-test (:use :cl :rucksack))

(cl:in-package :rucksack-object-test)

(defparameter *test-suite* #p"/tmp/rucksack-object-test/")

(defparameter *names* '("David" "Jim" "Peter" "Thomas"
                         "Arthur" "Jans" "Klaus" "James" "Martin"))

(defclass thingy ()
   ((frobosity :accessor frobosity :initarg :frobosity :initform 32)))

(defclass person (thingy)
   ((name :initform (elt *names* (random (length *names*)))
          :accessor name)
    (age :initform (random 100) :accessor age))
   (:metaclass persistent-class))

(defmethod print-object ((person person) stream)
   (print-unreadable-object (person stream :type t)
     (format stream "called ~S of age ~D"
             (name person)
             (age person))))

(defun test-create (&key (nr-objects 2))
   "Test creating a rucksack with many persons."
   (with-rucksack (rucksack *test-suite* :if-exists :supersede)
     (with-transaction ()
       (loop for i below nr-objects
          do (let ((person (make-instance 'person)))
               (add-rucksack-root person rucksack))))))

(defun test-get ()
   (with-rucksack (rucksack *test-suite*)
     (with-transaction ()
       (map-rucksack-roots (lambda (root)
                             (print (cons root (frobosity root))))
                           rucksack))))

If I call test-create and then test-get, I get unbound-slot errors  
for frobosity. I guess this makes sense, but I would have expected 32  
as the answer.

Thanks,

Cyrus




More information about the rucksack-devel mailing list