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