/* Compact Disc Collection in Prolog Information about a CD collection is stored in Prolog. Predicates byGroup, byPerson, and byComposer are used to retrieve CDs. */ % allByPerson(P) retreives all CDs of music in which P contributed. % To use: % % ?- allByPerson('Billy Joel'). % allByPerson(P):- ( byPerson(P,CD) % Person is a performer. ; byComposer(P,CD) % Person is a conductor. ), CD, % Match with database. write(CD),nl, % Write info. fail. % Backtrack. % % byGroup(G,CD) CD is bound to a term that would match a CD % of music by group (band) G. % byGroup(G,CD):-CD=cd(_,group(G,_),_). % % byPerson(P,CD) CD is bound to a term that would match a CD % of music in which person P performed. % byPerson(P,CD):- (var(P) ; atom(P)), CD=cd(_,Info,_), ( Info=symph(Comp,orch(_,Cond)), ( Comp=P ; Cond=P ) ; Info=conc(Comp,solo(Soloist,_),orch(_,Cond)), ( Comp=P ; Cond=P ; Soloist=P ) ; Info=group(_,P) ; Info=solo(P) ). % % byComposer(C,CD) CD is bound to a term that would match a CD % of music written by composer C. % byComposer(C,CD):- ( CD=cd(_,symph(C,_),_) ; CD=cd(_,conc(C,_,_),_) ). /* Compact Disc Data */ cd('Storm Front', solo('Billy Joel'), 1989). cd('Glass Houses', solo('Billy Joel'), 1980). cd('Communique', group('Dire Straits','Knopfer'), 1979). cd('Brothers in Arms', group('Dire Straits','Knopfer'), 1985). cd('Eroica', symph('Beethoven', orch('L.S.U. S.O.','Mike') ), 1971). cd('Horn Concerto', conc('Mozart', solo('Hoegner','Horn'), orch('Vienna P.','Boehm') ), 1980). cd('Jupiter', symph('Mozart', orch('Bavarian R.S.O','Kubelik') ), 1971). cd('Slavonic Dances', symph('Dvorak', orch('Royal P.O.','Dorati') ), 1971). cd('From the New World',symph('Dvorak', orch('Chicago S.O.','Levine') ), 1971). cd('Emperor', conc('Beethoven', solo('Serkin','Piano'), orch('Boston S.O.','Ozawa') ), 1983).