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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prolog problem is numbers

Status
Not open for further replies.

springy2003

Instructor
Jan 30, 2003
67
0
0
GB
Hi, I have a very simple prolog problem and I am not sure whats wrong. I have to evalute an integer and from this test will pick the right out come. Here is my prolog code.

rule(A,B,C,Z) :- A=<6, rule(one,Z).
rule(A,B,C,Z) :- A>6, rule(2,B,C,Z).
rule(2,B,C,Z) :- B=yes, rule(two,Z).
rule(2,B,C,Z) :- B=no, rule(3,C,Z).
rule(3,C,Z) :- C=yes, rule(three,Z).
rule(3,C,Z) :- C=no, rule(four,Z).
rule(one,'Return 1').
rule(two,'Return 2').
rule(three,'Return 3').
rule(four,'Return 4').

If I have a goal say:
rule(3,yes,yes,Z). for example it returns "Return 1" which is correct.

But if I do something like:
rule(10,no,no,Z). I would expect "Return 4" but what I get is "Return 1". Can someone please help me out here. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top