Wednesday, 15 January 2014

Prolog Mutual recursion -



Prolog Mutual recursion -

ok i'm writing code go through check each value mutual recursion in prolog. code far:

semestersok(sp) :- [prior|tail] = sp, sem1ok(sp). %% sem1ok(sp) :- checks semester 1 of sp ok sem1ok(sp) :- [sem1|tail] = sp, sem2ok(tail). %% sem2ok(sp) :- sem2ok(sp) :- [sem2|tail] = sp, sem1ok(tail).

i haven't set code in yet checking (there's 2 relations has check alternating values), i'm having problem code cycling through until has empty list, fails , comes false (no). since code isn't manipulating code believe should come true stands right now. why isn't it?

you need rules empty list. add together this:

sem1ok([]). sem2ok([]).

also, code might more intuitive if write (as distinction between rule matching empty list , 1 matching non-empty list more clear):

% rules sem1ok/1 sem1ok([]). sem1ok([sem1|tail]):- ok(sem1), % involving sem1 sem2ok(tail). % rules sem2ok/1 sem2ok([]). sem2ok([sem2|tail]):- ok(sem2), % involving sem2 sem1ok(tail).

recursion prolog mutual-recursion

No comments:

Post a Comment