[~/public_html/8710/f05][4:50pm] more datalog.pl
suppliers('S1','Jones','Atlanta').
suppliers('S2','Smith','Duluth').
suppliers('S3','Blake','Marietta').
parts('P1','Nut','Red','Atlanta').
parts('P2','Bolt','Blue','Wichita').
parts('P3','Screw','Red','Duluth').
parts('P4','Axle','Green','Atlanta').
projects('J1','Bicycles','Atlanta').
projects('J2','Motorcycles','Duluth').
spj('S1','P1','J1',100).
spj('S1','P2','J1',100).
spj('S2','P1','J1',100).
spj('S2','P2','J2',100).
spj('S3','P1','J1',100).
q1(X,Y) :- suppliers(X,Y,'Duluth').
answer1(L) :- setof([X,Y],q1(X,Y),L).
q2(X,Y) :- suppliers(X,Y,_), parts(U,_,'Red',_), spj(X,U,_,_).
answer2(L) :- setof([X,Y],q2(X,Y),L).
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,
told.
[~/public_html/8710/f05][4:51pm]
[~/public_html/8710/f05][4:51pm]
[~/public_html/8710/f05][4:51pm]
[~/public_html/8710/f05][4:51pm]
[~/public_html/8710/f05][4:51pm] pl
Welcome to SWI-Prolog (Multi-threaded, Version 5.4.7)
Copyright (c) 1990-2003 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- ['datalog.pl'].
% datalog.pl compiled 0.01 sec, 4,916 bytes

Yes
?- go.

Yes
?- halt.
[~/public_html/8710/f05][4:51pm]
[~/public_html/8710/f05][4:51pm]
[~/public_html/8710/f05][4:51pm]
[~/public_html/8710/f05][4:51pm] more f
Answer to Q1
[S2, Smith]

Answer to Q2
[S1, Jones]
[S2, Smith]
[S3, Blake]
