请帮忙解决一个简单的 Prolog 问题
我的程序中有以下 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它的工作原理正如你在我的 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.