[英]What's the difference between Prolog rules and queries?
I'm new to logical programming and find it difficult to understand the difference between rules and queries, I feel they are basically the same. 我是逻辑编程的新手,发现很难理解规则和查询之间的区别,我觉得它们基本相同。 Any help to clarify this would be greatly appreciated.
任何帮助澄清这一点将不胜感激。
Syntactically, they are largely the same; 从句法上讲,它们大致相同; "
p(1).
" could be either a rule or a query, depending on where you put it. “
p(1).
”可以是规则或查询,具体取决于您放置它的位置。
Semantically, they are not. 从语义上讲,它们不是。
" p(1).
" as a rule tells Prolog " p(1)
is true". “
p(1).
”作为一条规则告诉Prolog“ p(1)
是真的”。
" p(1).
" as a query asks Prolog "is p(1)
true?". “
p(1).
”作为查询询问 Prolog“ p(1)
真的吗?”。
A rule is a definition such as 规则是诸如的定义
foo(X) :- bar(X), baz(X).
as it appears in a Prolog program. 因为它出现在Prolog程序中。
A query is either the right hand side of a definition like the above, ie (bar(X), baz(X))
or what you type at the Prolog interpreter prompt to get the program running. 查询是上面定义的右侧,即
(bar(X), baz(X))
或您在Prolog解释器提示符下键入的内容以使程序运行。
A query is a statement you are asking to have proven (which in the process of doing so may instantiate variables, which can server as your "output"); 查询是您要求证明的语句(在此过程中可以实例化变量,可以将服务器作为“输出”); rules make up the "program" used to develop that proof.
规则构成用于开发该证明的“程序”。
Your intuition is correct: they're both variations on a Horn clause. 你的直觉是正确的:它们都是Horn条款的变体。 The basic structure of a Horn clause is:
Horn子句的基本结构是:
head(...) :- body.
If you have a head without a body, you have a fact. 如果你的头部没有身体,你就有了事实。 If you have both, you have a predicate.
如果你有两者,你有一个谓词。 If you have just a body, then you have a query.
如果您只有一个正文,那么您有一个查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.