7.8.2 Tracking new answers to monotonic tables
The prolog_listen/2 interface allows for tracking new facts that are added to monotonic tables. For example, we can print new possible connections from the above program using this code:
:- prolog_listen(connected/2, connection_change). connection_change(new_answer, _:connected(From, To)) :- format('~p and ~p are now connected~n', [From, To]).
Currently, failure of the hook are ignored. If the hook throws an exception this is propagated. The hook is executed outside the current tabling context.168The final behavior may be different in both aspects.
After loading the connected/2 program and the above declarations we can observe the interaction below. Note that query 1 establishes the dependencies and fills the tables using normal tabling. In the current implementation, possibly discovered connections do not trigger the hook.169This is likely to change in the future.. Adding a single link/2 fact links both locations to itself and to each other in both directions. Adding a second fact extends the network.
1 ?- connected(_,_). false. 2 ?- assert(link('Amsterdam', 'Haarlem')). 'Amsterdam' and 'Haarlem' are now connected 'Amsterdam' and 'Amsterdam' are now connected 'Haarlem' and 'Amsterdam' are now connected 'Haarlem' and 'Haarlem' are now connected true. 3 ?- assert(link('Leiden', 'Haarlem')). 'Leiden' and 'Haarlem' are now connected 'Haarlem' and 'Leiden' are now connected 'Amsterdam' and 'Leiden' are now connected 'Leiden' and 'Amsterdam' are now connected 'Haarlem' and 'Leiden' are now connected 'Leiden' and 'Haarlem' are now connected 'Leiden' and 'Amsterdam' are now connected 'Leiden' and 'Leiden' are now connected 'Amsterdam' and 'Leiden' are now connected true.
Status
Monotonic tabling is experimental and incomplete. Notably support for answer subsumption and call subsumption is probably possible and may greatly improve the application domain and resource usage. Monotonic tabling should work with both shared and private tables. Concurrency issues have not yet been tested though.