0
votes

In the bottom i gave link to whole program (ciao) to make help easier. I try to make in Prolog function that will be have list of questions like

 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]]]).

I know it look really messy but I really need help and will be grateful. Main function is checking which answer is the best (having biggest sum of keywords points). My problem is that all look fine(made some write() to see what happening) till it go to last function here :

count_pnt_keys()

Prolog checking all words if their equal but when is out from keywords should come back to function called it but its just 'no' . Maybe I should check if list is empty before I call again the same function with just Tail? How to do this?

rules:

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

and I call it:

test :-
write(AnswerFirst),
count_pnt(FirstPackOfAnswer,FirstPackofKeys,ReturnedListwithpoints),
write(ReturnedListwithpoints).

link to code (ciao) http://wklej.org/id/754478/

2

2 Answers

0
votes

You call count_pnt with three free arguments, which means that count_pnt will first unify all its arguments with an empty list. Upon backtracking the recursive count_pnt clause is called which leads to count_pnt_keys with again three free arguments, that will lead to Ah being unified with [] etc rather than a failure.

Do you really call count_pnt as suggested by the code for test?

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

should look like this that was a problem