[cl-store-devel] serialized class instance as document format

Sven Emtell sven.emtell at doremir.com
Tue May 10 17:37:32 UTC 2011


Thanks Alex!
For me I think it suffices using "(shared-initialize <my-instance>  
t)", then all unbound slots will be nicely initialized with  
their :initform value. I didn't know how the initialization worked -  
thanks for pointing me in the right direction.
Thoughts on using a serialized class instance as document format,  
anyone?
/Sven


10 maj 2011 kl. 19.02 skrev Alex Mizrahi:

> hello
>
>      SE>  I am planning to use cl-store to save and load documents  
> in an
>      application that I am developing.
>      What I want to save is a serialized class instance using cl-
>      store:store and then later be able to load it using cl- 
> store:restore.
>      What troubles me is that in future versions of my application,  
> there
>      may be new slots in the class. My tests reveal that such new  
> slots end
>      up being unbound when loading an old class instance (without the
>      slot). Instead I would like it to have the new slot set to
>      it's :initform value.
>      Is this possible?
>
>
> I'm not sure about cl-store specific solution, but here's how you can
> auto-initialize (on demand) any unbound slots:
>
> (defclass my-persistent-object () ())
>
> (defmethod slot-unbound (class (instance my-persistent-object) name)
>  ;; when we've got unbound slot
>  ;; try reinitializing it with initform via shared initialize
>  (shared-initialize instance (list name))
>  (if (slot-boundp instance name)
>      ;; if it becomes bound, call slot-value once again.
>      ;; (I hope it does not get into loop.)
>      (slot-value instance name)
>      ;; otherwise call next method which signals error
>      (call-next-method)))
>
> Then make my-persistent-object parent for all classes which need this
> init-on-demand behaviour.
>
> I never use unbound slots anywhere in a normal course of a program  
> (I use
> NIL if something does not exist), so this works fine.
>
> Even if you use unbound slots it is unlikely that you actually want  
> unbound
> slot condition to be signalled...
>
>
> _______________________________________________
> cl-store-devel mailing list
> cl-store-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/cl-store-devel





More information about the cl-store-devel mailing list