% Starting with Prova 1.90, retract/retractall remove facts or rules with
%    headers SUBSUMED by the provided fact pattern. This includes
%    both the cases of constants matching variables in the pattern and variables
%    that are not more general that those in the pattern 
% The example also demonstrates a new insert(fact) predicate that inserts a fact only after
%    checking that no facts subsumed by it are left in the KB. If a subsumed fact or rule
%    are found, the KB is not changed.

:- eval(ra002()).

ra002() :-
	println(["-----"]),
	% The first fact not more general than this is removed by retract below
	retract(f(ws.prova.examples.Portfolio.N,M)),
	f(X,Y),
	println([f(X,Y)]).
ra002() :-
	println(["-----"]),
	% Facts more general than this are not removed by retractall below 
	retractall(f(ws.prova.examples.IBMPortfolio.N,Integer.M)),
	f(X,Y),
	println([f(X,Y)]).
ra002() :-
	println(["-----"]),
	insert(f(ws.prova.examples.Portfolio.N,Integer.M)),
	% Does not add anything as it subsumes a fact already in the KB
	insert(f(ws.prova.examples.Portfolio.N,M)),
	f(X,Y),
	println([f(X,Y)]).

f(ws.prova.examples.IBMPortfolio.N,Integer.M).
f(ws.prova.examples.Portfolio.N,M).
f(ws.prova.examples.IBMPortfolio.N,Integer.M).
f(2,3).

% ==================
% This prints:
% -----
% ["f",ws.prova.examples.Portfolio.@@7,Y]
% ["f",ws.prova.examples.IBMPortfolio.@@9,java.lang.Integer.@@8]
% ["f",2,3]
% -----
% ["f",ws.prova.examples.Portfolio.@@11,Y]
% ["f",2,3]
% -----
% ["f",ws.prova.examples.Portfolio.@@12,Y]
% ["f",2,3]
% ["f",ws.prova.examples.Portfolio.@@14,java.lang.Integer.@@13]
