Writing a Prolog Rule

186 views Asked by At

Given that I have entered

maindish(thanksgiving, turkey). 
sidedish(thanksgiving,pie). 

into the factbase, I am supposed to write a rule called meal(Holiday, Food) – that will identify the type of food served on a given holiday. For example, if asked about thanksgiving, it will return turkey and pie as the options. So far I have:

meal(Holiday, Food):- maindish(Holiday,Food), sidedish(Holiday,Food).
write('For the holiday:'), write(Holiday),write('the meal(s)are:'), write(Food),nl.
1

There are 1 answers

0
CapelliC On
meal(Holiday, [F1,F2]) :- maindish(Holiday,F1), sidedish(Holiday,F2).

?- meal(thanksgiving, Foods).

although modelling fixed structure data with lists is not optimal.