% each call B in a clause body is denoted by pp(I,J,B) where
% I is the clause number and J the call number.

:- module(input,[load_file/1,my_clause/2]).

:- dynamic my_clause/2.

load_file(F) :-
    retractall(my_clause(_,_)),
	see(F),
	remember_all(1),
	seen.


remember_all(N) :-
	read(C),
	(
	    C == end_of_file -> true
	;
            N1 is N+1,
	    remember_clause(C,N),
	    remember_all(N1)
	).

remember_clause((A :- B),N) :-
	!,
	tuple2list(B,BL,N,1),
	assert(my_clause(A,BL)).

remember_clause(A,_N) :-
	assert(my_clause(A,[])).



tuple2list((A,As),[pp(I,J,A)|LAs],I,J) :-
	!,J1 is J+1,
	tuple2list(As,LAs,I,J1).
tuple2list(A,[pp(I,J,A)],I,J).


