I have 2 lists.
strong_price ([100,110,95,90]). plato_fuerte ([filete_de_cerdo, fillet_of_fish, pollo_asado, meatloaf]).
What I want to do is a query that when you enter one of the dishes you also see its price
I have 2 lists.
strong_price ([100,110,95,90]). plato_fuerte ([filete_de_cerdo, fillet_of_fish, pollo_asado, meatloaf]).
What I want to do is a query that when you enter one of the dishes you also see its price
Just as you are storing the plates and their prices, you have to get the position of the plate in one of the lists and then get the price for the position in the other.
plato(X,P) :-
plato_fuerte(Pls),
precio_fuerte(Prs),
nth0(I,Pls,X),
nth0(I,Prs,P).
The nth0(?Index, ?List, ?Elem)
predicate is true when Elem
is the element in the Index
position in the List
list.
Now you can list all the dishes next to their price:
?- plato(X,Y).
X = filete_de_cerdo, Y = 100 ;
X = filete_de_pescado, Y = 110 ;
X = pollo_asado, Y = 95 ;
X = albondigas, Y = 90.
Ask about the price of a specific dish:
?- plato(filete_de_cerdo,X).
X = 100.
Or ask for the dishes with a certain price:
?- plato(X,90).
X = albondigas.