11.07.2015 Views

CL-STORE: CL Serialization Package - Common Lisp.net

CL-STORE: CL Serialization Package - Common Lisp.net

CL-STORE: CL Serialization Package - Common Lisp.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 4: Customizing 54 Customizing4.1 About CustomizingEach backend in <strong>CL</strong>-<strong>STORE</strong> can be customized to store various values in a custom manner.By using the defstore- and defrestore- macros youcan dene your own methods for storing various objects. This may require a marginalunderstanding of the backend you wish to extend.eg.(in-package :cl-user)(use-package :cl-store)(setf *default-backend* (find-backend 'cl-store));; Create the custom class(defclass random-obj () ((a :accessor a :initarg :a)));; Register random object. This is specific to the;; cl-store-backend.(defvar *random-obj-code* (register-code 110 'random-obj));; Create a custom storing method for random-obj;; outputting the code previously registered.(defstore-cl-store (obj random-obj stream)(output-type-code *random-obj-code* stream)(store-object (a obj) stream));; Define a restoring method.(defrestore-cl-store (random-obj stream)(random (restore-object stream)));; Test it out.(store (make-instance 'random-obj :a 10) "/tmp/random")(restore "/tmp/random")=> ; some number from 0 to 9If you need to get fancier take a look at the macroexpansion of the customizing macros.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!