What underlying feature supports the pengine_input predicate?

I’m using: SWI-Prolog version 8.0.2 on Ubuntu Linux 18.04.

I am really pleased with the pengine_input feature in Pengines. It’s opens up a whole legion of interesting app possibilities. I am curious as to what underlying SWI-Prolog (i.e. - library, predicate, package, etc.) allows the SWI-Prolog engine to halt execution in the middle of a query being executed, and perform an asynchronous and apparently blocking wait for input? That’s a truly impressive feature!

Also, is it possible to freeze the complete execution state of an SWI-Prolog interpreter in the middle of a query execution, persist it to storage, and then restore it from storage later with it ending up in the same state as when it was stored/saved? Something akin to a Python pickle/unpickle operation?

Why is this so hard? It isn’t much different from read. You tell the client you want input and then you wait on a message queue until the client delivers the input.

With some limitations that would be quite feasible. Using qsave_program/2 you can already save the program. Saving an engine shouldn’t be too hard as the state is well isolated. Not sure how useful it is though.

1 Like

Perfect, thanks!:

http://www.swi-prolog.org/pldoc/doc_for?object=qsave_program/2

@jan - what is the complement function to qsave_program that loads a saved program? I’ve surveyed the docs and I don’t see anything like a function named qload_program.