Prolog错误:超出全局堆栈

时间:2016-02-19 11:44:10

标签: prolog

当我尝试运行此代码时,会返回错误" 退出全局堆栈"。 谁能帮我解决这个问题?

start:- findDiseases([headache,weakness,heartbeat,loose_concentration], Diseases),write(Diseases).

findDiseases(PositiveSymptoms, Diseases) :- findDiseases(PositiveSymptoms, Diseases, []).
findDiseases([], Answer, Answer).
findDiseases([H|T], Diseases, Answer) :-
    findall(Disease, (kb(Disease,Simptoms_list,Feauture_list),member(H,Simptoms_list);member(H,Feauture_list)), As),
    append(As, Answer, NewAnswer),
    findDiseases(T, Diseases, NewAnswer).

% kb(diagnosis,symptoms_list,features_list).    
kb(iron_def,[headache,dizziness,cold,weakness,fatigue,heartbeat,loose_concentration,swelling_tongue,breath],[gender,pregnancy,vitamin_poor_diet,fe,feritin,b12,hb,hct,mcv,plt,wbc,rtc]).
kb(thalass,[loose_appetite,painful_spleen,pale_skin],[gender,parent1,parent2,face_features,fe,feritin,b12,hb,hct,mcv,plt,wbc,hbf,hba1,hba2,rtc]).
kb(minor_thalass,[headache,fatigue,weakness,pale_skin,swelling_tongue,cold,heartbeat,loose_concentration,breath,dizziness],[vitamin_poor_diet,gender,pregnancy,parent1,parent2,hbaf,hba2,fe,feritin,b12,hb,hct,mcv,plt,wbc,rtc]).

1 个答案:

答案 0 :(得分:1)

...
findall(Disease, (
   kb(Disease,Simptoms_list,Feauture_list),(
     member(H,Simptoms_list);member(H,Feauture_list)
   )), As),
...

请注意添加的括号表示分离。当然,它有助于读取代码的可读性。