向用户提问时 Prolog 代码中的错误 [已编辑]
Error in Prolog Code in Asking questions to user [ Edited]
我是 prolog 语言的新手,我想实现 4 条规则
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
我需要在 Prolog 中编程的系统是:
打字时开始。系统要求用户输入环境,如果输入的文本是环境之一,系统应输出 stimulus_situation.
所以,我尝试编写这段代码,但它不起作用而且我不知道为什么,如果你能帮助我。
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))).
我为 2 条规则写了它来尝试,但它们不起作用。
提前致谢。
据我了解,您可以这样写评论:
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.
示例:
?- go.
What is the Environment? textbook.
stimulus situation :verbal
true.
?- go.
What is the Environment? machines.
stimulus situation :object
true.
我是 prolog 语言的新手,我想实现 4 条规则
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
我需要在 Prolog 中编程的系统是: 打字时开始。系统要求用户输入环境,如果输入的文本是环境之一,系统应输出 stimulus_situation.
所以,我尝试编写这段代码,但它不起作用而且我不知道为什么,如果你能帮助我。
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))).
我为 2 条规则写了它来尝试,但它们不起作用。
提前致谢。
据我了解,您可以这样写评论:
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.
示例:
?- go.
What is the Environment? textbook.
stimulus situation :verbal
true.
?- go.
What is the Environment? machines.
stimulus situation :object
true.