为什么在predsort上出现存在错误? [英] Why am I getting an existence error on predsort?

查看:72
本文介绍了为什么在predsort上出现存在错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按完成路径所需的距离对路径列表进行排序.我正在使用的Prolog代码如下.

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.

当我呼叫sortRoutes时,我从Prolog收到一个存在错误,说predsort不存在.但是,我使用的是sort模块,而且似乎没有任何改变.

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?

谢谢!

:- 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.

推荐答案

我认为distCompare应该是

I think distCompare should be

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

这篇关于为什么在predsort上出现存在错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆