I'm new to the prolog language and I want to implement a 4 rules which they are
Rule 1:
if the environment is papers
or the environment is manuals
or the environment is documents
or the environment is textbooks
then stimulus_situation is verbal
Rule 2:
if the environment is pictures
if the environment is illustrations
if the environment is photographs
if the environment is diagrams
then stimulus_situation is visual
Rule 3:
if the environment is machines
if the environment is buildings
if the environment is tools
then stimulus_situation is 'physical object'
Rule 4:
if the environment is numbers
or the environment is formulas
or the environment is 'computer programs'
then stimulus_situation is symbolic
The System That I need to program in Prolog is : when typing go. the system asks the user to Enter the Environment, If the entered text is one of the Environments the system should output the stimulus_situation.
So, I tried to write this code but It doesn't work And I don't know why if you can help me with that.
go:- check(Env), write('enviroment is :'),write(Env),nl,undo.
check(verbal):- verbal,!.
check(visual):- visual,!.
verbal :- verify(enviroment).
visual :- verify(pictures).
ask(Question) :-
write('What is the Env?!'),
write(Question), write('? '),
read(Response), nl,
( (Response == papers ; Response == manuals ; Response == manuals; Response == textbook)
-> assert(yes(Question)) ;
assert(no(Question)), fail).
:- dynamic yes/1,no/1.
verify(S) :- (yes(S) -> true ; (no(S) -> fail ; ask(S))).
I wrote it for the 2 rules in order to try but they won't work.
Thanks in Advance.
As I understood from your comments you could write:
go:- ask("What is the Environment",Response), check(Response,Result),write('stimulus situation :'),write(Result).
verify(X,Y) :- yes(X,Y) -> true.
check(X,Y):- verify(X,Y),!.
ask(Question,Response) :-
write(Question), write('? '),
read(Response), nl,
( (Response == papers ; Response == manuals ; Response == manuals; Response == textbook)
-> assert(yes(Response,verbal)) ;
(Response==machines)->assert(yes(Response,object))).
:- dynamic yes/2.
Example:
?- go.
What is the Environment? textbook.
stimulus situation :verbal
true.
?- go.
What is the Environment? machines.
stimulus situation :object
true.