buy( Person, Thing) :- needs( Person, Thing), price( Thing, Price), can_pay( Person, Price). price(cornflakes,2). price(frosties,3). price(branflakes,2). price(chocolate_cake,1). needs(antonia, frosties). needs(mark, branflakes). can_pay(antonia,4). can_pay(mark,2).
Queries :
buy(mark,frosties)
buy(mark,_)