Why am I getting an existence error on predsort?

泄露秘密 提交于 2020-01-05 07:35:02

问题


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:


I think distCompare should be

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


来源:https://stackoverflow.com/questions/19613641/why-am-i-getting-an-existence-error-on-predsort

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!