
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%% A simple analyzer %%%%%%%%%%%%%%%%%%%%%% 
%%%%%%%%%%%%% for set based groundness analysis %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%   Last revision: April 2002 (G.Rossi)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%A simple tool for showing how the set-based groundness analysis technique 
%for logic programs described in the paper at
%http://www.math.unipr.it/~gianfr/PROJECT/COFIN99/DPR.draft.SC.ps
%actually works.

%The following files are assumed to be stored in the same directory
%where this file is:
% - 'setlog.pl': the {log} interpreter
% - 'setloglib.slog': the {log} libraries
% - 'test_programs.txt': a collection of simple Prolog programs to be analyzed,  
%   along with the relevant CLP(SET) constraints which are tested by {log} to 
%   perform the groundness analysis
% - 'delta.slog': definitions of {log} predicates used by the analyzer.

%Execution. 
%Consult the simple analyzer (this file). As soon as consulting is 
%terminated, issue the goal 'analyze(N)' where N is the number of the
% sample Prolog program in 'test_programs.txt' you want to analyze
%Then supply the analyzer with the name P of the predicate and the number 
%of the argument of P you want to analyze, as requested by the analyzer.
%The analyzer will answer you with either "Surely ground" or "Possibly
%not ground".


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

:- consult(setlog).

analyze(N) :-
   ask_the_user(PName,NArg),
   setof(X,setlog_call(program(N,PName,NArg,X)),L),
   test_result(L),
   nl, write('test list for argument '), write(NArg), write(' of '),
   write(PName), write(': '), write(L), nl.

test_result(L) :-
   ground(L),!,
   nl, write('*** Surely ground ***'),nl.
test_result(_) :-
   nl, write('*** Possibly not ground ***'), nl.

ask_the_user(P,A) :-
   write('type the name of the predicate (followed by dot): '),
   read(P),
%   write('and its arity: '),
%   read(N),
   write('type the number of the argument you want to check (followed by dot): '),
   read(A).
%   (A > N,!, write('*** error ***'), fail; true). 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% start predicates
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

start :- 
   setlog_call(abolish),
   setlog_call(consult(lib)),
   setlog_consult('delta.slog'),
   setlog_consult('test_programs.txt'),
   nl,
   write('Give the goal ''analyze(N)'' where N is the number of the program '), 
   write('you want to analyze; supply the analyzer with the name of the '), 
   write('predicate and the number of the argument you want to analyze.'),
   nl,
   write('The analyzer will answer you with either "Surely ground" or "Possibly not ground').  

