2013-10-30 72 views
1

我正在处理的一个简单的Prolog程序的这部分应该找到距离给定点最远一定距离的坐标列表。我的代码工作,但也产生给定列表中的每个元素的错误。错误:类型错误:`file_path'预计

代码:

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。

谢谢你的时间!

回答

0

从第二个参数中删除Places,行至findall/3。这不是必要的,并且被解释为可能呼叫consult

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