%%%%%%%%%%% Forward chain for Hercule % 11.10.1997 12.05 :-[ru_com_h]. :-[ru_str_h]. :-[ru_mys_h]. /* * forward-chainer * finds a production rule that can be fired, * fires it, and informs the user, then calls * itself to repeat the process. */ think :- forall( rule(ID), pr_fired(ID)). think:-fail. pr_firing(N):- write('-------------------------------------->>>> '), write('Trying rule: '), write(N),nl. pr_fired(N):- write('-------------------------------------->>>> '), write('Fired rule: '), write(N),nl. /* * The remaining predicates are provided to make * writing and reading production rules easier. */ af(X) :- assert(fact(X)), print('fact asserted : '),write(X),nl. rf(X) :- retract(fact(X)), print('fact removed : '),write(X),nl. ag(X) :- assert(goal(X)), print('goal asserted : '),write(X),nl. rg(X) :- retract(goal(X)), print('goal deleted : '),write(X),nl. afw(X) :- assert(fact(X)). rfw(X) :- retract(fact(X)). %I don't know what's that... then. :-nl,write('Consulting facts...'),nl,nl,consult('fact_h.pl'). %The cycle of reading qloopread(Q):- write('>>>>>>>>>>>>>>>>>>>>>>>>>*****************************>>>>>>>>>>>>>>>>>>>>>>>>>'),nl, sleep(5), socket(ClientSocket), sock_writeln(ClientSocket,"page hercule &fact(stopread_herculog)"), sleep(1), repeat, socket(ClientSocket), sock_readln(ClientSocket,X), % writt(X), extrg(X,XG), extra(X,XA), not(ground(XA)), extrf(X,XX), ( ground(XX),remove_last(1,XX,XX1),name(XXC,XX1), ( XXC='fact(stopread_herculog)', write('<<<<<<<<<<<<<<<<<<<<<<<<<*****************************<<<<<<<<<<<<<<<<<<<<<<<<<'),nl,!; term_chars(X1,X),memansw(Q,X1) ); fail ). qloopread(Q):-fail. writt(X):- not(X=[]), name(XX,X), write(XX),nl. writt(X):-fail. memansw(Q,X):- (fact(register_command(Q,A1,A2)),af(answ(A1,A2,X)); fact(register_command(Q,B1,B2,B3)),af(answ(B1,B2,B3,X)); fact(register_command(Q,C1,C2,C3,C4)),af(answ(C1,C2,C3,C4,X))). memansw(_,_). rfmemansw(Q):- ( fact(register_command(Q,A1,A2)),rfw(register_command(Q,A1,A2)); fact(register_command(Q,B1,B2,B3)),rfw(register_command(Q,B1,B2,B3)); fact(register_command(Q,C1,C2,C3,C4)),rfw(register_command(Q,C1,C2,C3,C4))). rfmemansw(_).