Simple prolog query!!

Associate
Joined
6 Mar 2009
Posts
495
Im quite new to prolog and im stuck on what seems like a simple query. Heres whats in the database.

price(coffee,105).
price(tea,90).
price(cookie,105).
price(scone,95).
price(panini,225).
price(wrap,260).

drink(tea).
drink(coffee).

I want to write a query to answer as follows. What item that is not a drink costs 105 pence?? I cant figure out the NOT part.

Thanks
 
Maybe something like the below?

Code:
find_item(Price, Item) :-
price(Item,Price),
 \+ drink(Item).

While I haven't tested this because I'm at work (funnily enough I work with a language based on prolog) I would imagine if you call find_item(105, Item) it would return the items that match that aren't drinks.
 
Last edited:
Back
Top Bottom