% Since Prova 2.0.
% Demostrate RBSLA features available in Prova 2.0.
% consult and retractall with ID
% update
% transaction and integrity constraints

module("module1").

% Note that all the rulebases below should be consulted for the update and transaction functionality to work correctly
:-eval(consult('../ContractLog/list.prova')).
:-eval(consult('../ContractLog/testcase.prova')).
:-eval(consult('../ContractLog/utils.prova')).
:-eval(consult('../ContractLog/update.prova')).
:-eval(consult('../ContractLog/integrity.prova')).

:- eval(ex060()).

% integrity constraint
integrity(xor(e1(_),e2(_))).

ex060() :-
	% A fixed consult-id "id" is assigned
	consult(id,"d(a)."),
	d(X),
	println([X]),
	% Any facts or rules with consult-id="id" are removed
	retractall(id),
	d(Y),
	println([Y]).
ex060() :-
	% A fixed consult-id "id" is assigned
	consult(id,"d(X):-X=b."),
	d(X),
	println([X]),
	% Any facts or rules with consult-id="id" are removed
	retractall(id),
	d(Y),
	println([Y]).
ex060() :-
	% A dynamic unique consult-id based on conversation-id is assigned
	consult(XID,"d(X):-X=c."),
	d(X),
	println([X]),
	% Any facts or rules with consult-id=XID are removed
	remove(XID),
	d(Y),
	println([Y]).
ex060() :-
	% A static specified id is assigned
	add(id,"d(X):-X=_0.",[d]),
	d(X),
	println([X]),
	% Any facts or rules with consult-id=XID are removed
	remove(id),
	d(Y),
	println([Y]).
ex060() :-
	% A static specified id is assigned
	transaction(add(id,"e1(e1).")),
	e1(X),
	println([X]),
	% Does not succeed as an integrity constraint gets violated 
	transaction(add(id,"e2(e2).")),
	e2(Y),
	println([Y]).

% Outputs:
% a
% b
% c
% d
% e1
