I’m new to prolog. I think I’ve got the basics down but I’d like a bit
of help to get me started on what I’d like to accomplish.
I’d like a dynamic database over which I execute some goal query
every second. The goal itself has side effects and may assert and
retract over the database. I’d like the goal query to be running as
one process and in another process modify the database.
As a simple example imagine 3 tasks a, b, and c. c requires b to
complete, b requires a, and a has no prerequisites. I’d like to
accomplish task c. Notionally then:
:- dynamic aDone/0, bDone/0, cDone/0. doC :- bDone, writeln("c is done!"), asserta(cDone), !. % do c if b is done doC :- aDone, writeln("b is done"), asserta(bDone), !. % do c if b is done doC :- writeln("a is done"), asserta(aDone), !. % do a retractall :- % create fresh database retractall(aDone), retractall(bDone), retractall(cDone). start :- retractall, % start with no task complete repeat, doC, sleep(1.0), writeln("done iteration..."), % poll every 1s fail.
Now, in a separate process, I’d like to intervene on the database,
for example as
retract(bDone), retract(cDone), and have doC
automatically redo the b task in order to accomplish c.
I have no experience with threading; is that what I need here, or do I
need pengines? Could someone offer some suggested starting code?
Any help is much appreciated!