:- use_module(input).
:- use_module(lub_operations, [set_union/1]).
:- use_module(facts,[fact/1, flag/0]).
:- use_module(utilities, [showfacts/0]).


%% interface

  go(File,Goal) :-              % Goal is atomic
      retractall(fact(_)),      
      load_file(File),
      assert(fact(call(Goal))),
      iterate,
      showfacts.

%% control

  iterate :- operator, fail.
  iterate :- retract(flag), iterate.
  iterate.


%% logic 

  operator :- 
      my_clause(Head,Body),  
      fact(call(Head)),
      prove(Body), 
      set_union(ans(Head)).

  prove([B|Bs]) :- 
      set_union(call(B)),fail.
  prove([B|Bs]) :- 
      fact(ans(B)), prove(Bs).  
  prove([]).
