- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在学习“Prolog by Example”一书中的一个例子(Helder Coelho 和 Jose C Cotta)。
Write a program for designing an architectural unit
obeying the following specifications:
+ Two rectangular rooms
+ Each room has a window and interior door
+ Rooms are connected by interior door
+ One room also has an exterior door
+ A wall can have only one door or window
+ No window can face north
+ Windows cannot be on opposite sides of the unit
plan(FD,D1,W1,D2,W2) :-
frontroom(FD,D1,W1),
opposite(D1,D2),
room(D2,W2),
notopposite(W1,W2).
frontroom(FD,D,W) :-
room(D,W),
direction(FD),
dif(FD,D), % FD =\= D, % <- original was commented
dif(FD,W). % FD =\= W. % <- original was commented
room(D,W) :-
direction(D),
direction(W),
dif(D,W), % D =\= W, % <- original was commented
dif(W,north). % W =\= north. % <- original was commented
direction(north).
direction(south).
direction(east).
direction(west).
opposite(north,south).
opposite(south,north).
opposite(east,west).
opposite(west,east).
notopposite(D1,D2) :-
opposite(D1,D3),
dif(D2,D3). % D2 =\= D3. % <- original was commented
?- plan(west,D1,W1,D2,W2).
D1 = east,
W1 = south,
D2 = west,
W2 = south
[trace] ?- plan(west,D1,W1,D2,W2).
Call: (8) plan(west, _9632, _9634, _9636, _9638) ? creep
Call: (9) frontroom(west, _9632, _9634) ? creep
Call: (10) room(_9632, _9634) ? creep
Call: (11) direction(_9632) ? creep
Exit: (11) direction(north) ? creep
Call: (11) direction(_9634) ? creep
Exit: (11) direction(north) ? creep
Call: (11) north=\=north ? creep
ERROR: Arithmetic: `north/0' is not a function
最佳答案
应该是\==
比不正确的 =\=
.我不知道 =\=
除了算术不等式之外,还有别的意思。
1982年第3版为online和 =\=
是
even documented在 1978 年作为 DECsystem 10 Prolog 一部分的同一文档中。因此,即使在上述书籍的此先前版本中也存在矛盾。
正文到此为止。但你说得对dif/2
优于 (\==)/2
.见 this更多。
关于序言 - 为什么我应该使用 'dif' 而不是 '=\=',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60800828/
欢迎!这个系列的博文会带你使用golang语言来编写一个你自己的文本编辑器。 首先想说说写这个系列文章的动机。 其实作为校招生加入某头部互联网大厂一转眼已经快4年了。可以说该大厂算是比较早的用g
我想在序言中向数据库添加文本。就像是 adding :- tell('a.txt'), write('abc'), told. 但不会覆盖a.txt。我试过像这样使用append: append('a
我正在开发一款名为“狼山羊白菜”的益智游戏。编程语言是 Prolog。 change(e,w). change(w,e). move([X,X,Goat,Cabbage],wolf,[Y,Y,Goat
我对 Prolog 很陌生。 我有这样的图: edge(a,e). edge(e,f). edge(f,d). edge(d,a). 我将传递闭包定义为: p(X,Y) :- edge(X,Y). t
我想知道如何使用我拥有的元素获得一个漂亮的外观列表!我一直在尝试查找有关此内容的内容,但我发现的实际示例似乎都没有实际工作 这是我在网上找到的一种方法: create_list(Item, List,
我有一个使用约束用Sicstus Prolog编写的程序。 我的目标是使用labeling/2和其他方法来获取变量的随机实例化。 例子: X #> 2, Y #= 2*X, Z #<10 如果我用 L
我想知道,我知道你可以使用 assert添加事实或规则或其他任何内容,如果您已将谓词声明为 -:dynamic ,但这仅允许所做的更改仅保留在该 session 中,例如如果关闭 Prolog 窗口,
关于如何检索列表中重复次数最多的元素的任何想法。 即如下所示, ?- maxRepeated([1,2,7,3,6,1,2,2,3],M). M = 2. 最佳答案 我非常喜欢 Prolog 的关系功
my_reverse(L1,L2) :- my_rev2(L1,L2,[]). my_rev2([],L2,L2). my_rev2([X|Xs],L2,Acc) :- my_rev2(Xs,L2,[
我正在编写一个序言程序,该程序将检查两个数学表达式是否实际上相同。例如,如果我的数学表达式目标是:(a + b) + c,则以下任何表达式都被视为相同: (a+b)+c a+(b+c) (b+a)+c
我必须编写一个计算魔法矩阵的程序,我已经编写了我的代码并且它可以工作,但是我的排列非常慢。我需要一个更快的人可以帮助我请 这是代码: diabolico([A,B,C,D,E,F,G,H,I,J,K,
关于如何检索列表中重复次数最多的元素的任何想法。 即如下所示, ?- maxRepeated([1,2,7,3,6,1,2,2,3],M). M = 2. 最佳答案 我非常喜欢 Prolog 的关系功
我正在关注一个要求定义对称关系的 Prolog 教程。 例如,假设您在知识库中有以下事实: colleague(john,bob). 您还希望 colleague(bob,john) 是真实的,对于所
笔者从大学时期就开始接触的前端,在刚去实习的时候就被导师安排去做内网的一个小富文本工具。之后从毕业后干的第一份工作游戏客户端,到现在做着可视化相关的前端工作,都有在做富文本相关的内容。可以说是和 富文
我有一个对列表,想找到具有相应第一个值的元素。 ?- findconn1(9, [(9,[23,33]),(42,[21,322])], R). 所以在这种情况下,我希望结果是 (9,[23,23])
我试图让我的 ARM 围绕一些基本的序言,但在这个过程中有点挣扎。具体来说 - 我试图通过一个项目列表并将其逐项复制到一个新列表中。我可以让它反转,但我发现在不反转的情况下这样做会更棘手。 我一直在尝
当我的 friend 在学校开始学习 Prolog 时,我取笑他学习了无用的语言。然而,他向我展示了一些我什至不知道可能的东西;我想知道这个技术是从哪里来的。 技术是这样的: permutation(
我有下一条规则 % Signature: natural_number(N)/1 % Purpose: N is a natural number. natural_number(0). natura
我在理解为什么我在 prolog 中的代码根据我放置规则的顺序做某事时遇到了一些麻烦。 这是我的数据库: parent(tom, bob). parent(tom, liz). parent(mary
我正在尝试学习一些关于 swi-prolog 的知识(除了基本的、无用的程序)。 谁能解释(也许用伪代码)这个数独求解器和相关函数在做什么?如果您需要更多引用,可以在 swi-prolog 的 CLP
我是一名优秀的程序员,十分优秀!