It is possible to persist logical datastructures and state. It is not trivial to accomplish this and the interface must enable varying logic in order to meet
different demands. One important aspect is that a named variable need to be able to be looked up and at loading new data those variables need to be updated.
define-named-object enables this feature. Another feature is that you do not want to update a named objects value
make-shallow enables that and will force the persister to just remember the module/name path to it and not persist the value. Finally if you do not want to change the value directly, but a substructure inside of it, associate a getter and a setter via
associate-getter-setter and you will be able to maintain the integrity of variable values identity but still update the data. Guile structs, guile-log vlists and vhashes lists prolog variables and cons cells lists vectors closures primitive programs can all be persisted.
scm (make-persister #:key (file "persist.scm")), this will make a persistance object. You can add datastructures and retrieve datastructures and persist to disk. Datastructures are keyed in.
scm (persist-set! per key data), will add object
data associated with key
key to the persitance datastructure
scm (persist-ref per key), This will retrieve datastructure referenced by key
key in persistance datastructure
scm (load-persists per), will load the datastructure from the persistance file defined at the creation of the presistance datastructure.
scm (save-persists per), will save the datastructure from the persistance file defined at the creation of the presistance datastructure.
scm (define-named-object name obj), this is like
(define name obj), but
obj will, in case of an non immediate, attache a property that indecates to the persister that this object is the same as the named object meaning that in stead of creating a new object it will at loading use the named object.
scm (define-shallow-object name obj), this is like
(define name obj), but
obj will, in case of an non immediate, attache a property that indecates to the persister that this object is the same as the named object meaning that in stead of creating a new object it will at loading use the named object also this object is shallow meaning that the persister will not touch substructures of the object from the object reference point.
scm (make-shallow obj), This tells the persister to not grovel down the values of this datastructure. Returns the object with the association.
scm (associate-getter-setter obj set get), will add a getter
get and a setter
set to the non emmidiate object
obj. The persister will use the setter and getter to grovel into the objects datastructure to understand what to save and what not to save. Returns the objects with the associations.
(define-fluid-object name val), this is the same as
(define-named-object name (associate-getter-setter o fluid-ref fluid-set!))