% This example shows
%    - how repeated variable terms are instantiated during unification;
%    - how retractall can be used to remove rules matching a pattern
%      or those consulted from a particular source.
%    - reconsult and unconsult for externally consulted files.

:- solve(to_solve(X)).
:- solve_first(to_solve(X)).
:- eval(consult("ex022_include.prova")).
:- eval(ex022()).

ex022() :- 
	println(["==========ex022=========="]),
   test_equal(X,X),
	% retract all facts and rules for predicate test_equal
	% Note that in Prova [X,Y,Z...] is the same as X(Y,Z...)
	retractall([test_equal|_]),
	% The rule for "test_equal" is now gone: the following call will fail.
	test_equal(Y,Y).
ex022() :-
	test("Print this once after consulting from ex022_include.prova"),
	% reconsult(Filename) first removes everything consulted from Filename
	%    and then consults it again 
	reconsult("ex022_include.prova"),
	test("Print this once after reconsulting from ex022_include.prova"),
	% Unconsult all facts and rules consulted from this file
	% retractall(Filename) is the same as unconsult(Filename)
	unconsult("ex022_include.prova"),
	println(["***Nothing printed after this line***"]),
	test("Unable to print this").

test_equal(A,3) :-
	println(["A=",A," [printed only once]"]).

to_solve(1).
to_solve(2).