s()谓词在Prolog中做什么? [英] What does the s() predicate do in Prolog?
问题描述
我一直在尝试学习Prolog,并且对谓词s()的功能完全感到困惑. 我看到它经常使用,并且关于Prolog的互联网资源很少,我找不到答案.
I have been trying to learn Prolog, and am totally stumped on what the predicate s() does. I see it used often and there is so little resources on the internet about Prolog that I cannot find an answer.
例如.
/* sum(Is,S) is true if S is the sum of the list of integers Is. */
sum([],0).
sum([0|Is],S):-sum(Is,S).
sum([s(I)|Is], s(Z) ):-sum([I|Is],Z).
推荐答案
s/1
本身并不执行任何操作,并且实际上不是谓词.它们只是术语,代表其论证的后继者.因此,s(0)
用于表示0
(即1
)的后继者,s(s(0))
用于表示s(0)
(即2
)的后继者,依此类推.它们在Prolog中如此广泛,因为Prolog是执行符号计算的一种相当不错的语言,而即使简单的算术运算也感到笨拙,这意味着它们并未与编程范例无缝集成.
s/1
does not do anything in itself, and it's not really a predicate. They are just terms, a representation of the successor of their argument. So, s(0)
is used to represent the successor of 0
(i.e. 1
), s(s(0))
is used to represent the successor of s(0)
(i.e. 2
), and so on and so forth. They are so widespread in Prolog because Prolog is quite fine a language to perform symbolic computation, whereas even simple arithmetic operations feel clunky, meaning that they are not seamlessly integrated with the programming paradigm.
这篇关于s()谓词在Prolog中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!