From: Clemens Heitzinger
Subject: Re: save-object.lisp /persistent objects
Date: 
Message-ID: <B438CCD3.F6F%cheitzin@ag.or.at>
kp gores wrote in [BEITRAG] as [ADRESSE] on [DATUM]:

> and finally: has someone already ported  save-object to cmucl 18? it is a
> great tool everyone must be using.

My experience with save-object was that it's slow.  Maybe something like the
following is sufficient for your purposes? It doesn't however work with
recursive data structures (does save-object?).  The output of save-instance
can then be written to a file.  I'd call this poor man's persistent object
storage.


(defmethod save-instance ((object null))
  nil)

(defmethod save-instance ((object list))
  `(list ,@(mapcar #'save-instance object)))

(defmethod save-instance ((object string))
  object)

(defmethod save-instance ((object number))
  object)

(defmethod save-instance ((object standard-object))
  (save-instance-saving-slots object))

(defmethod save-instance-saving-slots ((object t))
  `(make-instance ',(class-name (class-of object))
     ,@(loop for slot-name in (mapcar #+ALLEGRO #'clos::slot-definition-name
                                      #+MCL #'ccl::slot-definition-name
                                      (#+ALLEGRO clos::class-slots
                                       #+MCL ccl::class-instance-slots
(class-of object)))
         when (and (slot-boundp object slot-name)
                       (slot-value object slot-name))
         collect (find-symbol (string slot-name) 'keyword)
         and collect (save-instance (slot-value object slot-name)))))

Yours,
Clemens
-- 
Clemens Heitzinger
http://ag.or.at:8000/~clemens   (Lisp related material)