/***********************************************************************/ /* Code for a new Prolog prompt */ /* */ /* Based on Sterling & Shapiro, p.186 */ /***********************************************************************/ prompt_me :- special_prompt, read(Goal), prompt_me(Goal). special_prompt :- write('Yes, spod? '). prompt_me(halt) :- !. prompt_me(Goal) :- isground(Goal), !, ground_solve(Goal), prompt_me. prompt_me(Goal) :- nonground_solve(Goal), prompt_me. ground_solve(Goal) :- solve(Goal), !, write('Oh, yes'), nl. ground_solve(Goal) :- write('Oh, no'), nl. nonground_solve(Goal) :- solve(Goal), write(Goal), nl, fail. nonground_solve(Goal) :- write('That''s your lot'), nl. solve(Goal) :- call(Goal). isground(Term) :- nonvar(Term), constant(Term). isground(Term) :- nonvar(Term), compound(Term), functor(Term, F, N), isground(N, Term). isground(N, Term) :- N > 0, arg(N, Term, Arg), ground(Arg), N1 is N - 1, isground(N1, Term). isground(0, Term). constant(X) :- integer(X). constant(X) :- atom(X). compound(X) :- not atomic(X).