Problem with short deadline

From: Yereth Jansen (yereth.no_at_spam.wanadoo.nl)
Date: 02/06/05


Date: Sun, 06 Feb 2005 17:22:15 +0100

Hello,

I have a problem with a prolog function I've written. The function is
defined as followed:

selectInStorage(
                part([A,B,C,Price1]),
                [part([A,B,C,Price2])|Tail],
                Tail,
                Price2
        ) :-
                Price2 =< Price1.

selectInStorage(
                part([A1, B1, C1, D1]),
                [part([A2, B2, C2, D2]) | Tail],
                [part([A2, B2, C2, D2]) | Rest],
                _
        ) :-
                selectInStorage(
                        part([A1, B1, C1, D1]),
                        Tail,
                        Rest,
                        _
                ).

This is the result of 2 tries in the commandline:

13 ?- selectInStorage(part([a,b,c,500]),[part([a,b,c,450])],List,Price).

List = []
Price = 450

Yes
14 ?- selectInStorage(part([a,b,c,500]),[part([a,b,c,550])],List,Price).

No
15 ?-
selectInStorage(part([a,b,c,500]),[part([a,b,c,550]),part([a,b,c,450])],List,Price).

List = [part([a, b, c, 550])]
Price = _G743

Yes

Now clearly, with the last result we are not getting the price we want.
The price should've been 450. He does find the right result, but does
not output Price2 correctly. Anyone any clue what we are doing wrong here?

Thanks in advance,
Yereth Jansen