Open aartaka opened 2 years ago
If I get it right, you want to skip the deserialize
call so that read-ing
would be enough, is this correct?
In any case, we would not replace cl-prevalence
, since write-nested-maybe-objects
is essentially what cl-prevalence does.
Note: can we leverage make-load-form
?
Looks interesting. You never know how much foresight you can discover in the spec ( ͡° ͜ʖ ͡°)
EDIT: an -> can
Actually make-load-form
would only work if we load
the file instead of merely read
-ing it. Not sure that would fit the bill here...
Actually
make-load-form
would only work if weload
the file instead of merelyread
-ing it. Not sure that would fit the bill here...
That's would work perfectly in conjunction with #5! Imagine: we serialize the data to a huge make-load-form
output, write
it to a file, complile
to fasl, and then load
it, getting the whole set of objects restored! \(@ ̄∇ ̄@)/
A small demo that seems to work on simple/standard types:
(defvar *data* nil)
(defun object->file (object file)
(with-open-file (f file :direction :output
:if-does-not-exist :create
:if-exists :supersede)
(prog1
(write `(setf *data* ,(make-load-form object)) :stream f)
;; Optional, to speed things up.
(compile-file file)
file)))
(defun file->object (file)
(load file)
*data*)
OK, but what abou the readtable trick from the original post?
Also before working on this, let's run some benchmarks (e.g. on Nyxt's GHT).
How about this: define a reader macro for classes and (de)serialize objects with this macro in
*readtable*
? Something like sharpsign-s reader macro for structures, but for classes. Maybe even rebind the structure one? Then we can rebind readtables to the new syntax for the time or reading:Benefits:
cl-prevalence
, I'm guessing).read
is (a lot, I'm guessing).Downsides: