2 (defgeneric persist-to
(v strm
))
3 (defmethod persist-to ((k number
) strm
)
6 (defmethod persist-to ((u tuple
) strm
)
7 (format strm
" (vcat~{ ~S~})" (tuple-elems u
)))
9 (defmethod persist-to ((a mtrix
) strm
)
10 (format strm
" (vcat~{ (cat~{ ~S~})~})"
13 (defun persist-var-to (k strm
)
14 (format strm
"(store ~S" k
)
16 (symbol-value (find-symbol k
:lineal.client-vars
))
21 ;V Write all variables in *clent-vars* to the stream V
22 ;V in a special format which uses lineal's calculator V
23 ;V syntax. For example, if we have a V
24 ;V number a, vector b, and matrix c, where V
29 ;V the data written to the stream is V
31 ; (store "b" (vcat 1 2 3))
32 ; (store "c" (vcat (cat 1 2) (cat 3 4))))
34 (defun save-to-stream (strm)
36 (append *saved-numbers
*
37 *saved-tuples
* *saved-matrices
*)
38 :do
(persist-var-to k strm
)))
40 (defun restore-from-stream (strm)
41 (let ((result (process-input-from-stream strm nil
)))
43 (format nil
"ERROR ~A" result
)
44 "Variables successfully restored.")))
46 ;V Save a session capture file.V
49 (file (make-pathname :name
"captured_session")))
51 (strm file
:direction
:output
52 :if-exists
:supersede
)
53 (save-to-stream strm
)))
55 ;V Restore from a capture file.V
58 (file (make-pathname :name
"captured_session")))
60 (with-open-file (strm file
:direction
:input
61 :if-does-not-exist nil
)
62 (if strm
(restore-from-stream strm
)
63 "File does not exist."))
65 (declare (ignore condit
))
66 "Something went horribly wrong.")))