Fork me on GitHub

@wombawomba just to make sure: it is already possible to preserve SCI state, but only in memory, when using an explicit ctx. But you are probably asking about saving to disk, turn off the computer and continue some other time right?


Well actually, it's both 🙂. Preserving it in memory would be useful for development purposes, but for production I would like to be able to move it between processes.


Would it help if I know that I can always just reconstruct the context when resuming?


You can record every expression that was used to get to that state and then replay


Hmm... how would I do that? Also, what if the expressions have side effects?


I'd also worry about the state becoming huge if I did something like that


Actually, I guess I could record all side-effectual function calls with return values, and just return those values until the state has caught up. Perhaps that's what you meant?


@wombawomba I mean, if you have made a context with (def ctx (sci/init {})) and then do something like (sci/eval-string* ctx "(def x 1)") , you could save (def x 1) somewhere to restore the exact same state later?


so instead of saving the state, save the events that lead to that state


Yeah okay. The thing is that I'm letting my eval-string calls run indefinitely, and I want to be able to pause them mid-computation.


However, what I'm thinking I could do is just: 1. Record every call (with responses) to a side-effectual function in my context, as a sort of trace. 2. When "pausing", just kill the SCI thread and freeze the trace. 3. When "resuming", give SCI a modified context, where all side-effectual functions are replaced with ones that just replay the thawed trace (until the eval has "caught up" with the trace, where I make them act as normal).


...actually, to do this, I would need to override all side-effectual functions in the default context as well — although I suppose that should be possible?


...and AFAICT the only functions I'd need to care about are rand, rand-int, rand-nth and random-sample. I'll just go ahead and replace those with my own 'traced' wrapper fns.


...hmmm, nondeterminism would cause problems. I'll have to wrap deref and realized? as well.