2017-01-15 16 views
0

をコンパイルするとき、私は構文エラーの前に:「終了」コード

syntax error before: 'end' 

を取得しています、私は割り当てのためにこのコードを実行するごとに単一の時間:

closest(_P, _PointList) -> 
    case (length(_PointList =:= 0)) of 
     true -> {0,0}; 
     false -> closest(_P, tl(_PointList), distance(_P, hd(_PointList)), 1) 
    end. 
    % Llength = length(_P), 

closest(P, _PointList, _Distance, _Index) -> 
    case (length(_PointList =:= 0)) of 
     true -> {_Index, _Distance}; 
     false -> 
      New_Distance = min(_Distance, distance(_P, hd(_PointList)), 
      case (New_Distance < _Distance) of 
       true -> closest(_P, tl(_PointList), New_Distance, _Index + 1); 
       false -> closest(_P, tl(_PointList), _Distance, _Index) 
      end 
    end 
end. 

誰かが、これはなぜ私が把握助けることができますハプニング?おかげ

答えて

2

min/2ため)がありませんでしたし、余分なend

があるべきだった:

closest(_P, _PointList, _Distance, _Index) -> 
    case (length(_PointList =:= 0)) of 
     true -> {_Index, _Distance}; 
     false -> 
      New_Distance = min(_Distance, distance(_P, hd(_PointList))), 
      case (New_Distance < _Distance) of 
       true -> closest(_P, tl(_PointList), New_Distance, _Index + 1); 
       false -> closest(_P, tl(_PointList), _Distance, _Index) 
      end 
    end. 
0

あなたはおそらくこれを書きたい:

closest(_P, []) -> {0, 0}; 
closest(P, [H|T]) -> 
    closest(P, T, distance(P, H), 0, 1). 

closest(_P, [], Distance, ClosestIndex, _Index) -> 
    {ClosestIndex, Distance}; 
closest(P, [H|T], Distance, ClosestIndex, Index) -> 
    case distance(P, H) of 
     New_Distance when New_Distance < Distance -> 
      closest(P, T, New_Distance, Index, Index + 1); 
     _ -> 
      closest(P, T, Distance, ClosestIndex, Index + 1) 
    end. 
0

これは私には不審に見える

case (length(_PointList =:= 0)) of 

以外にも、あなたがラインエラーが発見された数(または近く)を取得する必要

case length(_PointList) =:= 0 of 

であるべき。エラースタックトレースが確実に役立ちます。

関連する問題