Recursion Prolog递归停止

Recursion Prolog递归停止,recursion,prolog,Recursion,Prolog,在底部,我给了整个程序ciao的链接,使帮助更容易。 我尝试在Prolog函数中创建一个问题列表,如 questions([[[What, are,you,doing,?],[Where,am,I,Incorrect,?]]]). answers([[Im,doing,exercise],[I,do,nothing]],[[You,are,incorrect,at,'..'],[i,dont,know]]]). wordkeys([[[Incorrect,50],[doing,20]]])

在底部,我给了整个程序ciao的链接,使帮助更容易。 我尝试在Prolog函数中创建一个问题列表,如

 questions([[[What, are,you,doing,?],[Where,am,I,Incorrect,?]]]).
 answers([[Im,doing,exercise],[I,do,nothing]],[[You,are,incorrect,at,'..'],[i,dont,know]]]).
 wordkeys([[[Incorrect,50],[doing,20]]]).
我知道这看起来很混乱,但我真的需要帮助,我会很感激的。 主要功能是检查哪些答案是最好的,有最大的关键字点数和。 我的问题是,所有人都写了一些东西,看看发生了什么,直到它转到这里的最后一个函数:

count_pnt_keys()
Prolog检查所有单词是否相等,但何时从关键字中退出,应该返回到调用它的函数,但它只是“否”。也许我应该先检查一下列表是否为空,然后再调用同一个函数的justtail?如何做到这一点

规则:

count_pnt([],[],[]).
count_pnt([Ah|At],Keys,RList) :-      %choose one answer from answer list and go further
    count_pnt_word(Ah,Keys,Pnts),     %return sum of points for one answer
    count_ADD_POINT(RList,Pnts),      %not important here
    count_pnt(At,Keys,RList).         %call again with next question
/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
count_pnt_word([],[],0)
count_pnt_word([Ah|At],Keys,Pnts) :-  %choose one WORD from answer and go further
    count_pnt_keys(Ah,Keys,Pnts),
    count_pnt_word(At,Keys,Pnts).     %call recursion with next word from answer
/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
count_pnt_keys([],[],0)
count_pnt_keys(AWord,[Kh|Kt],Pnts) :- %check word with all keys for first question
    get_tail_h(Kh,KWORD,KPOINTS),     %just return head and tail from first key
    AWord==KWORD,                     %check if they are equal
    /*counting points*/ !,            %counting not important when end counting points go out to next
    count_pnt_keys(AWord,Kt,Pnts). %call again if not equal and try with next key
我称之为:

test :-
write(AnswerFirst),
count_pnt(FirstPackOfAnswer,FirstPackofKeys,ReturnedListwithpoints),
write(ReturnedListwithpoints).
链接到代码ciao

使用三个自由参数调用count\u pnt,这意味着count\u pnt将首先使用一个空列表统一其所有参数。回溯后,调用递归count_pnt子句,这将导致count_pnt_键再次具有三个自由参数,这将导致Ah与[]等统一,而不是失败

您真的按照测试代码的建议调用了count\u pnt吗

应该是这样的这是个问题

count_pnts(_,_,[],_).
count_pnt_word(_,[],_).
count_pnt_keys([],_,_).