How to use Prolog on tinman for Database Queries
The following is a sample file (called hw2.pro) which contains
several Prolog queries:
q1(X,Y) :- agents(X,Y,'Duluth',_).
answer1(L) :- setof([X,Y],q1(X,Y),L).
q2(X,Y) :- customers(X,_,C,_),agents(Y,_,C,_).
answer2(L) :- setof([X,Y],q2(X,Y),L).
...
...
...
Once the above file is prepared, you should append the
following Prolog code to the file hw2.pro.
output([]) :- !.
output([X|L]) :- write(X), nl, output(L).
go :- tell(f),
answer1(L1),write('Answer to Q1'), nl,output(L1), nl,
answer2(L2),write('Answer to Q2'), nl,output(L2), nl,
answer3(L3),write('Answer to Q3'), nl,output(L3), nl,
answer4(L4),write('Answer to Q4'), nl,output(L4), nl,
answer5(L5),write('Answer to Q5'), nl,output(L5), nl,
answer6(L6),write('Answer to Q6'), nl,output(L6), nl,
answer7(L7),write('Answer to Q7'), nl,output(L7), nl,
answer8(L8),write('Answer to Q8'), nl,output(L8), nl,
answer9(L9),write('Answer to Q9'), nl,output(L9), nl,
answer10(L10),write('Answer to Q10'), nl,output(L10), nl, told(f).
Then, you can do the following to execute all your queries:
$cprolog ~raj/mo or ~raj/grade
| ?- ['hw2.pro'].
| ?- go.
| ?- halt.
$
At this point, the output of the queries would have gone to
file named f. You should submit a printout of this file along
with the printout of hw2.pro.