错误:输入错误:'file_path'预期

时间:2013-10-30 14:51:54

标签: prolog swi-prolog

我正在研究的一个简单的Prolog程序的这一部分应该找到一个距离给定点最远一些距离的坐标列表。我的代码可以工作,但也会为给定列表中的每个元素生成错误。

代码:

nearby_places(Places, Position, Signal, NearbyPlaces) :-
    findall(
            X,
            (
                Places,
                member(X, Places),
                is_reachable(Position, X, Signal)
            ),
            NearbyPlaces
        ).

is_reachable(Position, Target, Signal) :-
    manhattan_distance(Position, Target, Distance),
    Distance =< Signal * 3.

manhattan_distance(pos(X1, Y1), pos(X2, Y2), Distance) :-
    Dx is X1 - X2,
    Dy is Y1 - Y2,
    ADx is abs(Dx),
    ADy is abs(Dy),
    Distance is ADx + ADy.

试运行

?- nearby_places([pos(0,0), pos(1,1), pos(2, 50), pos(4, 9)], pos(0,0), 10, N).
ERROR: Type error: `file_path' expected, found `pos(0,0)'
ERROR: Type error: `file_path' expected, found `pos(1,1)'
ERROR: Type error: `file_path' expected, found `pos(2,50)'
ERROR: Type error: `file_path' expected, found `pos(4,9)'
N = [pos(0, 0), pos(1, 1), pos(4, 9)].

我所做的所有测试都会产生正确的结果,但也会产生这些错误。 我在任何地方都找不到任何有用的东西。 我在Linux上使用SWI-Prolog 5.10.4。

感谢您的时间!

1 个答案:

答案 0 :(得分:0)

Places,的第二个参数中删除findall/3行。在那里没有必要,并且可能被解释为对consult的调用:

findall(
        X,
        (
            member(X, Places),
            is_reachable(Position, X, Signal)
        ),
        NearbyPlaces
    ).