我之前检查过的序言中的事实
我在序言中有这个知识库...
start :- navabi(C).
male(X,N) :-
write('Is this a male? '), flush_output,
read(yes).
navabi(N):- male(N) -> print('he is navabi') ; mirian(N).
mirian(N):- not( male(N)), print('she is ms.mirian').
female(X) :- not(male(X)).
问题是,当我启动这个程序并输入非男性的人时,程序会转到 mirian。然后我打印另一张,它再次查看那个人是否是男性(但是它大喊要注意这个“N”不是男性),但它再次询问“这是男性吗?”。 看来序言忘记了以前的知识。有人可以帮我解决这个问题吗?
问候。
I have this knowledge base in prolog...
start :- navabi(C).
male(X,N) :-
write('Is this a male? '), flush_output,
read(yes).
navabi(N):- male(N) -> print('he is navabi') ; mirian(N).
mirian(N):- not( male(N)), print('she is ms.mirian').
female(X) :- not(male(X)).
The problem is that when I start this program and enter someone who is not a male, the program goes to mirian. and then I print another one, and it again goes to see if that person is male ( however it shout be aware that this 'N' is not a male ) but it again asks 'Is this a male?'.
It seems that prolog forgets about the previous knowledge. Can any one help me with this?
regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你打电话给male/1,而(在你发布的代码中)只有male/2。这通常会导致异常,除非male/1被声明为动态的;那么,male(N) 就永远是假的。我猜想在一些序言变体中,即使它是静态的,它也总是可以被认为是错误的;你使用什么 prolog 版本?
断言新数据使用 asserta/1 或assertz/1;如您所见,prolog 没有内存!
you call male/1 while (in the code you posted) there is only male/2. this usually leads to an exception unless male/1 is declared as dynamic; then, male(N) will always be false. I guess that in some prolog variations it could always be considered false even if it's static; what prolog version are you using?
to assert new data use asserta/1 or assertz/1; prolog does not have memory as you noticed!