what I am trying to accomplish is using a database of disease facts
symptom(shingles,headache).
symptom(shingles,fever).
symptom(shingles,malaise).
symptom(shingles,headache).
symptom(smallpox,fever).
symptom(smallpox,rash).
and compare it with a list of symptoms from the user. I can currently get the symptoms from the user and add the disease to a list, however, I cant figure out how to loop through the entier database to add all the possible diseases it could be.
start:-
consult(diseases1),
getSymptoms(Symptoms),
write(Symptoms).
welcome:-
write('Welcome to the Disease Diagnostic Center'),nl,nl.
getSymptoms(Symptoms) :-
write('Please enter symptoms now, enter "Done" when finished: ' ),
read_string(user, "\n", "\r", _, Response),
(
Response == "Done"
->
Symptoms = []
;
atom_string(Symptom,Response),
valid_symptom(Symptom,Symptoms)
).
valid_symptom(Symptom,Symptoms) :-
(
symptom(_,Symptom)
->
getSymptoms(Symptoms0),
foreach(symptom(Y,Symptom),write(Y))
;
format('Invalid symptom: `~w''~n',[Symptom]),
getSymptoms(Symptoms0),
Symptoms = Symptoms0
).
So for example, the user enters fever as one of the symptoms, then the list should have in it shingles and smallpox. Currently I am able to write each possible disease to the screen, but I am not sure what to replace write with to be able to add each to a list.