我使用古老的Turbo Prolog,因为它包含在我们的课程中。为什么这个程序不工作?变量只能使用一次
domains
disease, indication = symbol
Patient = string
Fe,Ra,He,Ch,Vo,Ru = char
predicates
hypothesis(Patient,disease)
symptom(Patient,indication,char)
response(char)
go
clauses
go:-
write("What is patient's name?"),
readln(Patient),
symptom(Patient,fever,Fe),
symptom(Patient,rash,Ra),
symptom(Patient,head_ache,He),
symptom(Patient,chills,Ch),
symptom(Patient,runny_nose,Ru),
symptom(Patient,head_ache,He),
symptom(Patient,vomit,Vo),
hypothesis(Patient,Disease),
write(Patient," probably has ", Disease , "."),nl.
go:-
write("Sorry unable to seem to be diagnose disease"),nl.
symptom(Patient,Fever,Feedback) :-
Write("Does " , Patient , " have " , Fever , "(y/n) ?"),
response(Reply),
Feedback = Reply.
hypothesis(Patient, chicken_pox) :-
Fe = Ra = He = Ch = 'y'.
hypothesis(Patient, caner) :-
Ru = Ra = He = Vo = 'y'.
hypothesis(Patient, measles) :-
Vo = Ra = Ch = Fe = He = 'y'.
response(Reply):-
readchar(Reply),
write(Reply),nl.
我得到的警告变量只用于包含symtoms
的所有行。参数是否通过引用传递调用?当我通过Fe
到symptoms
值应该被复制到Fe
当我比较它在假设它应该相应地工作。 Turbo Prolog中的运营商工作非常奇怪。当它没有绑定到任何变量时,语句a = 3
将为a赋值3,并且当已经包含值a = 5
将检查a的值是否为5。
请帮助我为什么程序无法正常工作?
感谢提前:)
我对Turbo Prolog没有经验,但是在“正常”序言中,“=”正在做它应该做的事情。 '='不是关于算术评估,而是关于统一,'LHS = RHS'试图统一**'LHS'和'RHS',并根据需要绑定任何变量。 – rvirding 2010-08-21 15:50:37
@rvirding,你是对的统一。但是'='的规则是,如果变量未被绑定,'='将作为赋值运算符,并且如果绑定意味着它包含某个值,那么'='将作为比较运算符。 – TCM 2010-08-22 04:22:14
是的,但是你所描述的**是**统一,或者至少在一个简单的层面上。变量可以在嵌套的术语内。所以用'foo(X)= foo(3)',那么变量'X'将与'3'统一,绑定或匹配。 – rvirding 2010-08-22 18:02:12