我之前检查过的序言中的事实

发布于 2024-12-20 19:47:44 字数 422 浏览 5 评论 0原文

我在序言中有这个知识库...

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏至、离别 2024-12-27 19:47:44

你打电话给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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文