[CM] Saving entire state of the intrepreter?

bil at ccrma.Stanford.EDU bil at ccrma.Stanford.EDU
Fri Aug 14 13:34:54 PDT 2020


I think you can mimic cl-store in s7; for example
it's possible to call for-each on the repl's top let, omit functions 
that
aren't interesting, and write the others using format with ~W or 
object->string
with :readable.  In repl.scm the top let is (*repl* 'top-level-let), so 
say
we started that repl and typed:

<1> (define (f1 x) (+ x 1))
f1
<2> (define f2 (let ((y 3))
                  (lambda (z)
                    (+ y z))))
f2

Now we can save this to a file via:

(call-with-output-file "saved-repl.scm"
   (lambda (p)
     (for-each
       (lambda (var&val)
         (unless (eq? (car var&val) 'exit)
           (format p "(define ~S ~W)~%" (car var&val) (cdr var&val))))
       (*repl* 'top-level-let))))

The file has:

(define f2 (let ((y 3)) (lambda (z) (+ y z))))
(define f1 (lambda (x) (+ x 1)))

This can be used for (almost) anything (I used the top-level-let
above for simplicity).  You can use (*s7* 'file-names) to
find what files need to be loaded.



More information about the Cmdist mailing list