请帮忙解决一个简单的 Prolog 问题

发布于 2024-10-04 21:05:48 字数 559 浏览 0 评论 0原文

我的程序中有以下 Prolog 代码:

conn([oxford_circus, baker_street], 4).
conn([baker_street, kings_cross], 5).
conn([oxford_circus, warren_street], 3).
conn([warren_street, tottenham], 2).
conn([oxford_circus, tottenham], 2).
conn([tottenham, holborn], 1).
conn([holbor, kings_cross], 4).

s(N, M, C) :-
  conn(L, C),
  member(N, L),
  member(M, L).

现在我将 s 谓词称为 s(oxford_circus, M, C).,但不幸的是它确实失败了,而不是告诉我例如:

M = baker_street
C = 4

我确信这是一个非常简单的错误,但似乎我找不到它:(
预先感谢您的任何指导!

干杯!

I have the following Prolog code in my program:

conn([oxford_circus, baker_street], 4).
conn([baker_street, kings_cross], 5).
conn([oxford_circus, warren_street], 3).
conn([warren_street, tottenham], 2).
conn([oxford_circus, tottenham], 2).
conn([tottenham, holborn], 1).
conn([holbor, kings_cross], 4).

s(N, M, C) :-
  conn(L, C),
  member(N, L),
  member(M, L).

Now I call the s predicate as s(oxford_circus, M, C)., but unfortunately it does fail, instead of telling me for example:

M = baker_street
C = 4

I am sure this is a very simple error, but it seems I can't find it :(
Thanks in advance for any guidance!

Cheers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

前事休说 2024-10-11 21:05:48

它的工作原理正如你在我的 swi prolog 中所期望的那样。
难道您需要使用正确的命令行吗?
例如,swi prolog 的典型问题是不使用 -s 或 -c 标志。

It works as you expect in my swi prolog.
Could it be than you need to use a proper command line?
For example the typical problem with swi prolog is not to use -s or -c flag.

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