% nacteni:
/* ['8.3_27.pl']. */

:- op( 800, fx , if ),
op( 700, xfx, then),
op( 300, xfy, or),
op( 200, xfy, and).

% rules
if
  mokra_chodba and sucha_kuchyn
then
  tece_v_koupelne.

if
  mokra_chodba and sucha_koupelna
then
  problem_v_kuchyni.

if
  okno_zavrene or neprsi
then
  nezatika_zvenci.

if
  problem_v_kuchyni and nezatika_zvenci
then
  tece_v_kuchyni.

% facts

fact(mokra_chodba).
fact(sucha_koupelna).
fact(okno_zavrene).

forward :- new_derived_fact( P), !,
           write('Derived: '), write( P), nl,
           assert( fact( P)),
           forward
           ; write('No more facts').
            
new_derived_fact( Concl) :- if Cond then Concl,
    \+ fact( Concl),
    composed_fact( Cond).
    
composed_fact(Cond) :- fact( Cond).
composed_fact(Cond1 and Cond2) :- composed_fact( Cond1),
                                  composed_fact(Cond2).
composed_fact(Cond1 or Cond2) :- composed_fact( Cond1) ; 
                                 composed_fact( Cond2).

:- forward.
