You write readPain(X)=='y'.
. But Prolog interprets this as (==)(readPain(X),'y')
. Prolog sees readPain(X)
as a term, not as a predicate call.
In order to ask a if a person has pain
, you should use:
pain :-
readPain(y).
Now it will query the user, and if the user writes y.
, the predicate will succeed. So can ask:
patient :- cancer; diabetes.
cancer :- pain.
diabetes :- sugar.
pain :-
readPain(y).
sugar:-
readSugar(y).
readPain(X) :-
write('is it painful?'),nl,read(X).
readSugar(X) :-
write('Do you have sugar problems?'),nl,read(X).
The read/1
predicate queries the user for a term, parses that term, and will unify the parameter with that term. So that means that after you have called readPain(X)
, X
will have the value y
in case the user has written y.
. By performing unification with y
, we check if that is indeed the case.
readSugar(X) == 'y'
? – Willem Van Onsem