Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

prolog rule

Status
Not open for further replies.

edeita2

Programmer
Joined
Apr 25, 2004
Messages
2
Location
US
I am practicing some prolog, below is my code for a prolog predicate(rule) to check the inventory levels, so I try to write a reorder predicate which takes "Part" as an argument and print a message 'Time to reorder' if the inventory level is less than 10, it should normally print that, if it is true, but I`m having some difficulties, could anyone show me where I go wrong?
here`s the rule(prolog predicate):

code:
inventory(part1, 10).
inventory(part2, 7).
inventory(part3, 30).
inventory(part4, 73).
inventory(part5, 3).
reorder(Part):-inventory(Part,Y), Part is (Y < 10), write('time to reorder').
 
Solution for: prolog rule
I found out where I went wrong myself, here`s the solution for future Prolog victims:

code:
inventory(Part, Quant):- Quant < 10.
reorder(Part):-inventory(Part, Quant),Quant < 10, write('Time to reorder!').


result of prolog session:

code:
| ?- reorder(Lessinquantity).
Time to reorder!
Lessinquantity = part2
Time to reorder!
Lessinquantity = part5


I`m grateful to myself, thank you myself for helping me !

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top