2013-10-30 93 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 
    ).