Assistance writing a Prolog rule

101 views Asked by At

Given that I have entered the following facts into the factbase. Each sidedish has two ingredients:

maindish(thanksgiving, turkey). 
sidedish(thanksgiving,pie). 
ingredient(pie,spice).
ingredient(pie,sugar). 

I have written the following rule to return the dishes for a given holiday:

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

?- meal(thanksgiving, Foods).

I am trying to write a rule called ingredientList that will identify the type of ingredients needed for each holiday. By associating the dishes and ingredients for each given holiday.

1

There are 1 answers

0
false On
ingredientlist(Holiday, Ingredients) :-
   setof(Ingredient,
          Dishes^Dish^ ( meal(Holiday,Dishes),
                         member(Dish, Dishes),
                         ingredient(Dish, Ingredient) ),
         Ingredients).