Prolog SWI序言:错误:未定义的过程:军事状态/2

Prolog SWI序言:错误:未定义的过程:军事状态/2,prolog,Prolog,我试图用Prolog制作一个简单的决策树来回答这个问题。我承认有些语法我并不完全理解,但从我所了解的情况来看,我认为我的程序应该可以工作。代码如下。无论何时运行它,都会出现多个错误。我得到的错误的完整列表如下: ERROR: Undefined procedure: martial_status/2 ERROR: However, there are definitions for: ERROR: marital_status/2 ERROR: ERROR: In: ERR

我试图用Prolog制作一个简单的决策树来回答这个问题。我承认有些语法我并不完全理解,但从我所了解的情况来看,我认为我的程序应该可以工作。代码如下。无论何时运行它,都会出现多个错误。我得到的
错误的完整列表如下:

ERROR: Undefined procedure: martial_status/2
ERROR:   However, there are definitions for:
ERROR:         marital_status/2
ERROR: 
ERROR: In:
ERROR:   [13] martial_status(_5306,_5308)
ERROR:   [12] not(user:martial_status(_5342,_5344)) at c:/program files/swipl/boot/init.pl:346
ERROR:   [11] ask_marital_status(_5368,_5370) at c:/users/itsar/onedrive/documents/prolog/decision-tree.pl:9
ERROR:   [10] stable_risk(_5394) at c:/users/itsar/onedrive/documents/prolog/decision-tree.pl:20
ERROR:    [9] invest(_5418,oil) at c:/users/itsar/onedrive/documents/prolog/decision-tree.pl:24
ERROR:    [8] main(_5444,oil) at c:/users/itsar/onedrive/documents/prolog/decision-tree.pl:6
ERROR:    [7] <user>

你能清理一下你的错误吗?你的评论似乎混为一谈。!错误很明显:您定义了一个
婚姻状况/2
谓词,但您正在调用
婚姻状况/2
。一个简单的输入错误。@DavidTonhofer是的,Logtalk linter会打印一条警告,说明谓词
军事状态/2
被调用,但没有定义或声明(假设代码封装在对象或模块中)。@false这里的问题似乎是输入错误。通常,这个问题应该以“简单的打字错误”结束。正如你所看到的,已经有一次投票结果接近。我不明白这个悬赏。什么问题的更纯粹的解决方案?
marital_status(joe,married).
income(joe,60000).
mortgage(joe,20000).
age(joe,45).

main(X,Z):-var(X), write('what is your name?'),read(X), invest(X,Z),!.
main(X,Z):-invest(X,Z),!.

ask_marital_status(X,Y):-marital_status(X,Y).
ask_marital_status(X,Y):-
   not(martial_status(X,Y)),
   write('what is your marital status: married or single?'),
   read(Y), nl,
   asserta(marital_status(X,Y)).

ask_income(X,Y):-income(X,Y).
ask_income(X,Y):-
   not(income(X,Y)),
   write('what is your annual income?'), nl,
   read(Y),
   asserta(income(X,Y)).

ask_mortgage(X,Z):-mortgage(X,Z).
ask_mortgage(X,Z):-
   not(mortgage(X,Z)),
   write('what is your mortgage?'),
   read(Z), nl,
   asserta(mortgage(X,Z)).

ask_age(X,A):-age(X,A).
ask_age(X,A):-
   not(age(X,A)),
   write('what is your age?'),
   read(A),
   nl,
   asserta(age(X,A)).

moderate_risk(X):-
   ask_marital_status(X,Y), Y=married,
   ask_income(X,I), I=<50000,
   ask_mortgage(X,Z), Z=<50000,!.
moderate_risk(X):-
   ask_marital_status(X,M), M=married,
   ask_income(X,I), I=<50000,!.
moderate_risk(X):-
   ask_marital_status(X,M), M=single,
   ask_income(X,I), I=<35000,!.

stable_risk(X):-
   ask_marital_status(X,M), M=married,
   ask_income(X,I), I=<50000,
   ask_mortgage(X,Z), Z>50000,!.
stable_risk(X):-
   ask_marital_status(X,M), M=single,
   ask_income(X,I), I>35000,
   ask_age(X,A), A>50, !.

high_risk(X):-
   ask_marital_status(X,M), M=single,
   ask_income(X,I), I>35000,
   ask_age(X,A), A=<50, !.

invest(X,oil):-stable_risk(X),!.
invest(X,telecommunications):-moderate_risk(X),!.
invest(X,computers):-high_risk(X),!.