How do I make a recursive list that checks company rankings?

Posted by Sera on Stack Overflow See other posts from Stack Overflow or by Sera
Published on 2011-01-09T17:41:58Z Indexed on 2011/01/09 18:53 UTC
Read the original article Hit count: 159

Filed under:
|
|

I have a set of companies in rank order. I want my rule to check if the companies in a specified list are in rank order, and for the rule to recur until all companies in the list have been checked.

I currently have the following:

isOrder([]).
isOrder([COM1,COM2|T]) :-
    rank(COM1,D), rank(COM2,E),
    D<E,
    print("in order"),
    isOrder([COM2|T]).

However, this does not seem to work. Sometimes, the recursion goes on forever without ending, and sometimes the recursion doesn't work at all. This is when I vary the code to try and get the correct answer.

Can anybody help me? I have just started Prolog and my understanding of it is severely limited. Any help would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about list

Related posts about recursion