Reputation: 796
I have this proLog environtment (cooking stuff):
first("ajo-blanco").
first("brandada-de-bacalao").
second("empanadilla-de-jamon-y-soja").
second("pollo-al-ajillo").
category("ajo-blanco", aperitivos_tapas).
category("brandada-de-bacalao", aperitivos_tapas).
category("empanadilla-de-jamon-y-soja", aperitivos_tapas).
category("pollo-al-ajillo", carnes_y_aves).
same_category(Primero, Segundo) :-
category(Primero, Type) = category(Segundo, Type).
menu_simple(Primero, Segundo) :-
first(Primero),
second(Segundo),
same_category(Primero, Segundo).
I define 4 plates, 2 first plates and 2 second plates. A menu_simple object is a menu that has 2 plates: 1 first and 1 second and this two plates are not from the same category, so the 2 correct combinations for the menu_simple predicate are:
"ajo-blanco" + "pollo-al-ajillo", "brandada-de-bacalao" + "pollo-al-ajillo"
My problem is that the following predicate:
same_category(Primero, Segundo)
always returns false when I try it.
same_category("pollo-en-salsa", "ajo-blanco").
returns false (this is correct, they dont have the same category)
same_category("ajo-blanco", "empanadilla-de-jamon-y-soja").
returns f alse too (this is wrong, they dont have the same category)
I am sure that I'm missing something since im new into prolog. Any help would be apreciated.
Thanks in advance.
Upvotes: 1
Views: 633
Reputation: 66190
I'm not a Prolog expert but... if you write
same_category(Primero, Segundo) :-
category(Primero, Type) = category(Segundo, Type).
you ask that category(Primero, Type)
and category(Segundo, Type)
are equal; and this is true only when Primero = Segundo
.
But Primero
is a first, Segundo
is a second and there is no intersection between firsts and seconds.
If you want to check that Primero
and Segundo
are in the same category, you should check that the type of Primero
is the same type of Segundo
, that is
same_category(Primero, Segundo) :-
category(Primero, TypeP),
category(Segundo, TypeS),
TypeP = TypeS.
that is equivalent to
same_category(Primero, Segundo) :-
category(Primero, Type),
category(Segundo, Type).
Another observation: if you want that "this two plates are not from the same category", your actual menu_simple/2
is wrong because select a Primero
and a Segundo
in the same category.
Upvotes: 3