/marshal

simply dump and load lisp objects without configuration

Primary LanguageCommon Lisp

Use Cases

Marshal List

(fmarshal:load (fmarshal:dump (list 1 (list 2 3) 4)))
;; => (1 (2 3) 4)

Marshal Vector

(fmarshal:load (fmarshal:dump #(1 #(2 3) 4)))
;; => #(1 #(2 3) 4)

(fmarshal:load (fmarshal:dump (make-array (list 2 2) :initial-element 0)))
;; => # #2A((0 0) (0 0))

Marshal Hashmap

(let ((h (make-hash-table :test 'equal)))
  (setf (gethash "blub" h) t)
  (gethash "blub" (fmarshal:load (fmarshal:dump h))))
;; => T

Marshal Object

(defclass test-object ()
  (test-slot))

(let ((o (make-instance 'test-object)))
  (setf (slot-value o 'test-slot) "blub")
  (slot-value (fmarshal:load (fmarshal:dump o)) 'test-slot))
;; => "blub"

Marshal References

(defclass test-inherited (test-object)
  (object-slot))

(let ((o (make-instance 'test-inherited)))
  (setf (slot-value o 'test-slot) "blub")
  (setf (slot-value o 'object-slot) o)
  (let ((loaded-object (fmarshal:load (fmarshal:dump o))))
    (values
     (slot-value loaded-object 'test-slot)
     (eq loaded-object (slot-value loaded-object 'object-slot)))))
;; => "blub", T