如何在 prolog 过程中的最后一个参数之后插入附加参数?
我是学习序言的新手,我想知道,如果我们有一些像这样的程序
father("Nic","Adam").
,我想编写一个函数,它将为此添加新的值,
father("Nic","Adam","something"..)
我该怎么做?使用列表?或者什么?
I am new to learning prolog, and I want to know, if we have some procedure like
father("Nic","Adam").
and I want to write a function that it will add new value to this
father("Nic","Adam","something"..)
how can I do this? Using list? Or what?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
快速回答:你不想这样做。
更长的答案:
father/2
谓词有一定的含义,即对于father(X,Y)
X
是的父亲>Y。
father/3
谓词完全是另一回事。你想通过第三个论点实现什么目标?通常,您使用附加规则,这些规则从father/2
谓词派生事物,甚至将其解析为father/3
参数。主要问题仍然是:第三个论点的目的是什么?例如,如果您希望您的解析基于相应的
father/2
谓词的存在而适用于某些特定的第三个参数,您可以执行father(X, Y, 'something') : -father(X,Y)
如果您有相应的father/2
事实,则会成功。PS:一定要学习你的术语。在 Prolog 中,我们不谈论过程,也不编写函数。相反,我们有谓词、事实、规则、...
PPS:我不确定您正在使用哪种 Prolog 实现,但您可能想要使用
'something'
而不是"something"
。后者通常创建一个字符代码列表,而不是一个字符串:Quick answer: You don't want to do that.
Longer answer: The
father/2
predicate has a certain meaning, namely that forfather(X,Y)
X
is the father ofY
. Afather/3
predicate is a different thing altogether. What do you want to achieve with that third argument? Normally, you use additional rules, which derive things from thefather/2
predicate, or even resolve it to afather/3
argument.The main question remains: what's the purpose of the third argument? If you want your resolution to work for certain specific 3rd arguments based on the existance of a corresponding
father/2
predicate for example, you could dofather(X, Y, 'something') :- father(X,Y)
which will succeed if you have a correspondingfather/2
fact.PS: Do learn your terminology. In Prolog we don't speak of procedures and we don't write functions. Instead we have predicates, facts, rules, ...
PPS: I am not sure which Prolog implementation you are using, but you might want to use
'something'
instead of"something"
. The latter usually creates a list of character codes, not a string:简单地写
为 As 谓词就已经定义了它。这就像陈述一个事实:您声明
father(nic, adam)
是true
,然后您可以使用这些预期结果执行以下命令:Simply writing
As a predicate already defines it. It is like stating a fact: you declare that
father(nic, adam)
istrue
, then you can execute the following with these expected results :