% file: tutors.pro % author: Robert Keller % purpose: Prolog tutorial example involving tutors, dorms, etc. :- ensure_loaded('enumerate.pro'). % lives(N, D) means that person named N lives in dorm D lives('John', 'East'). lives('Naima', 'South'). lives('Alice', 'West'). lives('Toshiko', 'East'). lives('Roy', 'North'). lives('Albert', 'South'). % takes(N, D, C) means that person named N takes course C in department D takes('John', 'CS', 60). takes('Naima', 'CS', 60). takes('Alice', 'CS', 60). takes('Toshiko', 'CS', 5). takes('Albert', 'CS', 60). takes('Roy', 'Math', 55). takes('Naima', 'Math', 55). takes('Alice', 'Math', 70). takes('Toshiko', 'Math', 80). takes('Albert', 'Math', 55). % tutors(N, D, C) means that person named N tutors course C in department D tutors('John', 'CS', 5). tutors('Naima', 'CS', 5). tutors('Roy', 'Math', 3). tutors('Alice', 'Math', 55). tutors('Albert', 'Math', 4). % livesInEast(X) means that person named X lives in east. livesInEast(X) :- lives(X, east). % canTutor(X, Y) means that person X can tutor person Y (because X is tutoring % a course that Y is taking) canTutor(X, Y) :- tutors(X, Dept, Number), takes(Y, Dept, Number). % knows(X, Y) means that person X knows person Y knows(X, Y) :-knows(X, Y, _). % knows(X, Y, R) means that person X knows person Y for reason R % For example, R can be 'living' because both live in the same dorm, % or 'tutoring' because Y can tutor X. knows(X, Y, living) :- lives(X, Z), lives(Y, Z). knows(X, Y, tutoring) :- canTutor(Y, X).