This is my first experience with Prolog. I am at the beginning stages of writing a program that will take input from the user (symptoms) and use that information to diagnose a disease. My initial thought was to create lists with the disease name at the head of the list and the symptoms in the tail. Then prompt the user for their symptoms and create a list with the user input. Then compare the list to see if the tails match. If the tails match then the head of the list I created would be the diagnosis. To start I scaled the program down to just three diseases which only have a few symptoms. Before I start comparing I need to build the tail of list with values read from the user but I can't seem to get the syntax correct.
This is what I have so far:
disease([flu,fever,chills,nausea]).
disease([cold,cough,runny-nose,sore-throat]).
disease([hungover,head-ache,nausea,fatigue]).
getSymptoms :-
write('enter symptoms'),nl,
read(Symptom),
New_Symptom = [Symptom],
append ([],[New_symptom],[[]|New_symptom]),
write('are their more symptoms? y or n '),
read('Answer'),
Answer =:= y
-> getSymptoms
; write([[]|New_symptom]).
The error occurs on the append line. Syntax Error: Operator Expected. Any help with this error or the design of the program in general would be greatly appreciated.
appendand(. That should clear up the syntax error on that line. - lurkerappend([], [New_symptom], [[] | New_symptom])doesn't seem logical. Note that ifAis a list, then[A]is a different list, which consists of one element, namely, the listA. That is, it's a list of lists which contains one element. You haveNew_symptom = [Symptom], then in yourappendyou have[New_symptom]which is equivalent to[[Symptom]]which is not the same as[Symptom], etc. So, yes, you should review Prolog lists. See, 99 Prolog Problems as exercise examples. - lurker