
200 Logic Programming With Prolog
Question 5
It will be assumed that the file test1.txt contains
first.
second.
third.
fourth.
end.
and file test2.txt contains
first.
xxxx.
third.
fourthxxx.
end.
A possible definition of compare is:
compare(File1,File2):-
seeing(S),compfile(File1,File2),
see(File1),seen, see(File2),seen,see(S).
compfile(File1,File2):-
see(File1),read(X),see(File2),read(Y),
comp(X,Y),process(X,Y,File1,File2).
comp(A,A):-write(A),write(' is the same as '),
write(A),nl.
comp(A,B):-write(A),write(' is different from '),
write(B),nl.
process(end,end,_,_).
process(_,_,File1,File2):-compfile(File1,File2).
?- compare('test1.txt','test2.txt').
first is the same as first
second is different from xxxx
third is the same as third
fourth is different from fourthxxx
end is the same as end
yes