Why am I getting an existence error on predsort?

2019-08-15 13:17发布

I am trying to sort a list of paths by the distance it takes to complete them. The Prolog code I'm using is below.

When I call sortRoutes, I get an existence error from Prolog saying that predsort doesn't exist. However, I am using the sort module and that doesn't seem to change anything.

I can't seem to figure out why this isn't working. Am I doing anything wrong?

Thanks!

:- use_module(library(sort)).

sortRoutes(DistRoutes, SortedRoutes) :-
    predsort(distCompare, DistRoutes, SortedRoutes).

distCompare(Comp, E1, E2) :-
    my_nth(2, E1, Dist1),
    my_nth(2, E2, Dist2),
    compDists(Dist1, Dist2).

compDists(>, Dist1, Dist2) :-
    Dist1 > Dist2.
compDists(<, Dist1, Dist2) :-
    Dist1 =< Dist2.

1条回答
爷的心禁止访问
2楼-- · 2019-08-15 13:40

I think distCompare should be

distCompare(Comp, E1, E2) :-
    my_nth(2, E1, Dist1),
    my_nth(2, E2, Dist2),
    compDists(Comp, Dist1, Dist2).
查看更多
登录 后发表回答