Fork me on GitHub
#sci
<
2021-11-04
>
borkdude07:11:38

@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?

wombawomba07:11:22

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.

wombawomba07:11:04

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

borkdude07:11:15

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

wombawomba08:11:45

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

wombawomba08:11:16

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

wombawomba08:11:26

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?

borkdude08:11:01

@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?

borkdude08:11:42

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

wombawomba08:11:40

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.

wombawomba08:11:06

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).

wombawomba08:11:39

...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?

wombawomba08:11:39

...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.

wombawomba09:11:54

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