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

Alex Mizrahi alex.mizrahi at gmail.com
Tue May 10 17:02:08 UTC 2011


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... 





More information about the cl-store-devel mailing list