PDA

View Full Version : Prolog rule


edeita2
04-24-2004, 03:34 PM
I am now 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):

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').

edeita2
04-25-2004, 04:33 PM
I found out where I went wrong myself, here`s the solution for future Prolog victims:

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

result of prolog session:

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

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

GnuVince
04-25-2004, 06:45 PM
Heh ;) I don't think I've ever seen anybody post about Prolog here before, and I don't believe many members know it. I do not. Functional languages for which you can get help here are O'Caml, SML, Scheme, Haskell and Common Lisp (whether you consider it a functional language is a debate subject by the way). Not sure what other functional languages guys around here are familiar with.