Prolog:无法增加复杂项内变量的值
因此,我正在处理一个序言问题,在一个复杂的术语中定义了一个状态,当我尝试在此复杂术语中增加x的值时,没有任何
CurrentState(left, x, y).
test = CurrentState(left, x,y),
newX = x + 1,
write(newX).
事情发生吗?
So I'm working on a prolog problem where a state is defined in a complex term, When I try to increase the value of x inside this complex term nothing happens for example
CurrentState(left, x, y).
test = CurrentState(left, x,y),
newX = x + 1,
write(newX).
Is there a workaround for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实和谓词需要从小写字母开始。
变量需要从大写字母开始。
=
不是分配,并且Prolog Predicates不是函数调用,并且您永远都不会使用test
。即使那样,当您没有给出X值任何值时,您还是要
X + 1
做什么?这没有比左 + 1
这样写的更有意义。这一切都更像是:
然后,
在此之后,您仍然不想将状态存储为Prolog数据库中的事实并删除/断言。
Facts and predicates need to start with a lowercase letter.
Variables need to start with an uppercase letter.
=
is not assignment, and Prolog predicates aren't function calls, and you never usetest
anyway.Even then, what do you want
x + 1
to do when you haven't given any value for x? It makes no more sense thanleft + 1
written like that.It would all be more like:
Then
After that you still don't want to be storing the state as a fact in the Prolog database and removing/asserting it.