2012-11-10 1 views
1

작은 예를하는 무엇이 잘못되었는지 알아낼 수 없습니다, 프롤로그를 배우려고, 나는 그것은 작동하지 않는 특정 pozition

domains 
    element = symbol 
    list = element* 
    position = integer 
predicates 
    insert (element, position, list, list) %(input,input,input,output) 
clauses 
    insert (E,_,[],[E]). 
    insert (E, 1,[H|T],[E|[H|T]]).  %(I insert E on the "first" position) 
    % I get errors how E and T are not bound. I have no idea how to make them bound 
    insert (E,P,[H|T],[H1|T1]) :- 
      P > 1, 
      P1 = P - 1, 
      insert (E,P1,T,T1). 

에서 목록에서 기호를 삽입 할 ...하지만 이유를 모르겠다. 글쎄 그것은 다소 효과가있다. 모든 symbolName=_을 표시하는 대신 outputList = [NEW_LIST]을 표시하고 outputList = [_,_,_,_]을 표시하고 싶습니다.

답변

0

분명히 기호 데이터 형식에 문제가 있습니다. 정수를 사용하면 문제가 해결됩니다.

또한,이 필수적인 것입니다 :

domains 
    element = integer 
    list = element* 
    position = integer 
predicates 
    insert (element, position, list, list) %(input,input,input,output) 
clauses 
    insert (E,_,[],[E]). 
    insert (E, 1,[H|T],[E|[H|T]]). 
    insert (E,P,[H|T],[H|T1]) :- % has to be "H" (or anything else) in both 
      P > 1,     % so prolog understands what we are trying to do 
      P1 = P - 1,    % don't really understand why though 
      insert (E,P1,T,T1).  % I might be wrong