/* **************************************************************
	Query module 
**************************************************************** */

:- op(1180,fx,[trans]).

trans(X) :- 
	cleanup, !,
	parse_body(X,L,query),
	write_new_rules,
	assert((query :- L)), !,
	inserting(tr), call(L), deleting(tr).


% remove some useless rules from database

cleanup :-
	retract((query :- _)),
	cleanup.
cleanup :-
	cleanup_temp.

cleanup_temp :-
	retract(looplist(LList)),
	clean_looplist(LList),
	assert(looplist([])).

clean_looplist([]).
clean_looplist([Pred|Rest]) :-
	remove_all(Pred),
	clean_looplist(Rest).

remove_all(Pred) :-
	retract((Pred :- _)),
	remove_all(Pred).
remove_all(_).


