
/* Adapted from Clocksin, W.F., Mellish, C.S., "Programming in Prolog"
   (3rd Ed.) Springer-Verlag, 1987 */

client(bob).
client(dwight).

staff(bob).

% Allow staff to have overdue books: first variant using cut & fail
% book_overdue(X,_) :- staff(X), !, fail.

book_overdue(bob, book100).

general_facility(X) :- basic_facility(X).
general_facility(X) :- additional_facility(X).

additional_facility(borrowing).
additional_facility(inter_library_loan).

basic_facility(references).
basic_facility(enquiries).


facility(Person, Facility) :-
        book_overdue(Person, _),
        !,                        
        basic_facility(Facility).


/*
% Allow staff to have overdue books: better alternative using NAF
facility(Person, Facility) :-
        \+ staff(Person),
        book_overdue(Person, _),
        !,                              
        basic_facility(Facility).
*/

facility(_, Facility) :- general_facility(Facility).


% ?- client(X), facility(X,Y).

% ?- book_overdue(X,Y).
/* 
  The answer to the above is correct for the default version.
  The cut & fail variant masks that bob has overdue books.
  The NAF variant yields the correct answer.
*/