4 (defgeneric persist-to
(v strm
))
5 (defmethod persist-to ((k number
) strm
)
8 (defmethod persist-to ((u tuple
) strm
)
9 (format strm
" (vcat~{ ~S~})" (tuple-elems u
)))
11 (defmethod persist-to ((a mtrix
) strm
)
12 (format strm
" (vcat~{ (cat~{ ~S~})~})"
15 (defun persist-var-to (k strm
)
16 (format strm
"(store ~S" k
)
18 (symbol-value (find-symbol k
:lineal.client-vars
))
23 ;V Write all variables in *clent-vars* to the stream V
24 ;V in a special format which uses lineal's calculator V
25 ;V syntax. For example, if we have a V
26 ;V number a, vector b, and matrix c, where V
31 ;V the data written to the stream is V
33 ; (store "b" (vcat 1 2 3))
34 ; (store "c" (vcat (cat 1 2) (cat 3 4))))
36 (defun save-to-stream (strm)
38 (append *saved-numbers
*
39 *saved-tuples
* *saved-matrices
*)
40 :do
(persist-var-to k strm
)))
42 (defun restore-from-stream (strm)
43 (let ((result (process-input-from-stream strm nil
)))
45 (format nil
"ERROR ~A" result
)
46 "Variables successfully restored.")))
48 ;V Save a session capture file.V
51 (file (make-pathname :name
"captured_session")))
53 (strm file
:direction
:output
54 :if-exists
:supersede
)
55 (save-to-stream strm
)))
57 ;V Restore from a capture file.V
60 (file (make-pathname :name
"captured_session")))
62 (with-open-file (strm file
:direction
:input
63 :if-does-not-exist nil
)
64 (if strm
(restore-from-stream strm
)
65 "File does not exist."))
67 (declare (ignore condit
))
68 "Something went horribly wrong.")))