% Small helpers for expert systems %:- set_prolog_flag(discontiguous_warnings, off). %:- set_prolog_flag(unknown, fail). :- multifile goal/1. %:- dynamic(goal/1). %:- use_module(library(lists)). %%%% THIS LINE MAKES IN WORK (I hope) in SWI and SICSTUS4 get0(C):- get_code(C),!. test_goal(G):- goal(G), other_explanations(G). ask_user(Goal):- write('Is it true that '), write(Goal), write(?), get0(C), (C= 10 -> true ; skip_line), % end-of-line trouble (C= 0'y -> true ; C= 0'Y -> true ; C= 0'n -> fail ; C= 0'N -> fail ; write('Didn''t get you. Please reply with y, Y, n, or N followed by .'),nl, ask_user(Goal)). % ask user in backward chaining reasoning. goal(G):- (\+ \+ can_question(G)), ask_user(G). other_explanations(G):- write(G), write(' is true. Do you want me to check other ways?'), get0(C), (C = 10 -> true; skip_line), (C = 10 -> true ; C= 0'y -> fail ; C= 0'Y -> fail ; C= 0'n -> true ; C= 0'N -> true ; C= 0'; -> fail ; write('Didn''t get you. Please reply with y,Y,n,N or semicolon followed by .'),nl, other_explanations(G)).