- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
获得正确的术语是成功传达概念的一部分,当在 SO 中使用错误的术语时,带有 Prolog 标签的受访者会很好地指出错误。
在阅读 William F. Clocksin 于 1997 年 ( WorldCat ) 的“条款和效果 - 工作程序员的序言编程”中是一段
A Prolog program consists of a collection of procedures. Each procedure defines a particular predicate, being a certain relationship between its arguments. A procedure consists of one or more assertions, or clauses. It is convenient to think of two kinds of clauses: facts and rules.
最佳答案
来自 Prolog ISO 标准
ISO/IEC 13211-1 (First edition 1995-06-01)
Information technology - Programming languages - Prolog
Part 1: General Core
3.7 argument: A term which is associated with a predication or compound term.
3.9 arity: The number of arguments of a compound term. Syntactically, a non-negative integer associated with a functor orpredicate.
3.10 assert, to: To assert a clause is to add it to the user-defined procedure in the database defined by the predicate ofthat clause.
3.19 body: A goal, distinguished by its context as part of a rule (see 3.154).
3.21 built-in predicate: A procedure whose execution is implemented by the processor (see 8).
3.32 clause: A fact or a rule. It has two parts: a head, and a body.
3.35 complete database The set of procedures with respect to which execution is performed (see 7.5).
3.37 compound term: A functor of arity
N
,N
positive, together with a sequence ofN
arguments.3.45 control construct: A procedure whose definition is part of the Prolog processor (see 7.8).
3.52 database: The set of user-defined procedures which currently exist during execution (see 7.5).
3.57 directive: A term
D
which affects the meaning of Prolog text (see 7.4.2) and is denoted in that Prolog text by the directive-term:-(D)
.3.59 dynamic (of a procedure): A dynamic procedure is one whose clauses can be inspected or altered during execution, for example byasserting or retracting clauses (see 7.5.2).
3.72 fact: A clause whose body is the goal
true
. NOTE - A fact can be represented in Prolog text by a term whose principal functor is neither(:-)/1
nor(:-)/2
.3.77 functor: An identifier together with an arity.
3.81 goal: A predication which is to be executed (see body, query, and 7.7.3).
3.84 head (of a rule): A predication, distinguished by its context.
3.88 identifier: A basic unstructured object used to denote an atom, functor name or predicate name.
3.129 predicate: An identifier together with an arity.
3.131 predicate indicator: A compound term
A/N
, whereA
is an atom andN
is a non-negative integer, denoting one particular procedure (see 7.1.6.6).3.133 predication: A predicate with arity
N
and a sequence ofN
arguments.3.136 procedure: A control construct, a built-in predicate, or a user-defined procedure. A procedure is either static or dynamic. Aprocedure is either private or public (see 7.5).
3.141 Prolog text: A sequence of read-terms denoting directives and clauses (see 6.2, 7.4).
3.143 query: A goal given as interactive input to the top level.
3.154 rule: A clause whose body is not the goal
true
. During execution, if the body is true for some substitution, then the head is also true for that substitution. A rule is represented in Prolog textby a term whose principal functor is(:-)/2
where the first argument is converted to the head, and the second argument is converted to the body.3.164 static (of a procedure): A static procedure is one whose clauses cannot be altered (see 7.5.2).
3.185 top level: A process whereby a Prolog processor repeatedly inputs and executes * queries.
3.195 user-defined procedure: A procedure which is defined by a sequence of clauses where the head of each clause has the samepredicate indicator, and each clause is expressed by Prolog text orhas been asserted during execution (see 8.9).
h(A,B,C) :- g(A,B),h(B,C),j(A,C).
<-------------------------------> - A (HORN) CLAUSE, which is also a RULE.
<------------------> - BODY of the RULE, which also a GOAL.
... only one literal: ATOMIC GOAL.
<------> - HEAD of the RULE, which can appear
as GOAL depending on context.
f(A,B,C). - A CLAUSE with the elided body `true`.
This is a FACT, but _not_ a RULE.
Also called a UNIT CLAUSE.
f(A,B,C) :- true. - Same as above, still not a RULE.
f(A,B,C) :- !. - Is it a RULE? We don't know!
:- f(A,B,C). - A DIRECTIVE.
:- (foo(bar)). - Another DIRECTIVE.
在
Horn Clause 的条目中可以找到略有不同的定义。一个维基百科。特别是,“事实”被称为“没有变量的单元子句”——这与 ISO 定义不符。
A/N
(
functor/arity
),有符号
A//N
,它不在 ISO 标准中(或者还没有,请参阅
this draft )。它告诉读者这个谓词用在
Definite Clause Grammar (DCG) 中。除了指定的参数数量外,还为输入“差异列表”(或“列表差异”)对采用 2 个隐藏参数。
3.19 non-terminal indicator: A compound term
A//N
whereA
isan atom andN
is a non-negative integer, denoting one particularnon-terminal
nt//n
到谓词
nt/n+2
.但是,不能依赖精确的翻译方式和通过调用相应谓词直接调用非终结符的结果,即未定义具有相同名称和两个额外参数的谓词。特别是第二个附加参数必须小心处理。直接使用可能会违反坚定性,尤其是在使用
dcg-semicontext 时.
Queries and directives are ways of directing the system to executesome goal or goals. (...) The principal use for directives (as opposedto queries) is to allow files to contain directives that call variouspredicates, but for which you do not want to have the answers printedout. In such cases you only want to call the predicates for theireffect, i.e. you do not want terminal interaction in the middle ofconsulting the file.
module
指示:
This directive can only be used as the first term of a source file. Itdeclares the file to be a module file, defining a module named Module.
This section describes directives which manipulate attributes ofpredicate definitions.
:- use_module(library(clpfd)).
空头规则
:- foo
,可以解释为
false :- foo
在 Prolog 中不使用来表达约束“foo 永远不是这种情况”。在
Answer Set Programming 的实现中就是这样使用的像“ASP Prolog”(它具有 Prolog-y 语法,但与 Prolog 完全不同)。
"A built-in predicate is a procedure which is provided by astandard-conforming processor"
The word functor was borrowed by mathematicians from the philosopherRudolf Carnap, who used the term in a linguistic context; seefunction word.
In linguistics, function words (also called functors) are wordsthat have little lexical meaning or have ambiguous meaning and expressgrammatical relationships among other words within a sentence, orspecify the attitude or mood of the speaker.
p(X)
,在这种情况下,它是一个原子目标,或由子目标组成的树,例如
p(X),q(Y)
因为
,
是主仿函数
(',')/2
的谓词.
p(X) -> q(Y) ; r(Z)
, 主仿函数
;
(不是
->
)绝对是一个目标。
call/1
这样的元谓词。例如:
X=(Z is 1+2), call(X).
.
u v w
:
foo(X,Y,Z) :- format("~q ~q ~q\n", [X,Y,Z]).
maplist(foo, [u],[v],[w]). % call "foo" with 3 arguments
maplist(foo(u), [v],[w]). % call closure foo(u) with 2 arguments
maplist(foo(u,v) ,[w]). % call closure foo(u,v) with 1 argument
关于谓词与过程与谓词指示器的说明
fact
arity 2 计算阶乘函数:
fact/2
是谓词指示符,并且
fact(0,1) :- !.
fact(X,F) :- Xp is (X-1), fact(Xp,Fp), F is (Fp*X).
是可能的对应程序。
The collection of clauses for a given predicate is called a procedure.
?- X is 5 * 3.
X = 15.
关于prolog - 这个 Prolog 术语是否正确? (事实、规则、程序、谓词……),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49898738/
我正在学习序言。 在我看来,prolog 的规则(关系和简单的事实)是“肯定的”——他们说的是或可能是真的。 向 prolog 程序添加新的此类规则只会增加“正面”知识。它不能添加“负面”事实来说明某
希望你一切都好。我是 prolog 的新手,我在编写代码时遇到问题。这段代码的目的很简单。它将列表中的每个元素添加到最后一个。我可以用 Java 做的事情是: static void add(
在closed-world assumption下, what is not currently known to be true, is false Prolog 的语义通常被称为遵循封闭世界假设,
我正在 Prolog (swi-prolog) 中做我的第一步,但无法解决以下问题:如何将存在量化的规则包含在我的事实中;具体来说,我如何包含句子“每个人都是某人的 friend ”\forall x
我知道如何以过程方式(即,在 C++、Java 等中)对 BST 执行范围查询,但我发现很难转换为 Prolog 语言。 程序的方式应该是这样的: http://www.geeksforgeeks.o
Prolog 中是否有(相对)当前最佳实践的引用资料?一本适合没有学习过逻辑编程或“Prolog 的工艺”等高级文本的商业 Prolog 开发人员? 有很多通用教程,但我能找到的关于最佳实践的唯一一个
这是CFG: S -> T | V T -> UU U -> aUb | ab V -> aVb | aWb W -> bWa | ba 所以这将接受某种形式的: {a^n b^n a^m b^m |
我目前有以下问题,我想用 Prolog 解决。这是一个简单的例子,很容易在 Java/C/whatever 中解决。我的问题是,我认为与 Java 的思想联系太紧密,无法以利用 Prolog 逻辑能力
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我无法理解差异列表,尤其是在这个谓词中: palindrome(A, A). palindrome([_|A], A). palindrome([C|A], D) :- palindrome(A
(这不是一个类(class)作业问题。只是我自己的个人学习。) 我正在尝试在 Prolog 中进行练习以从列表中删除元素。这是我的代码: deleteall([],X,[]). deleteall([
我最近试图了解 Prolog,它似乎可以很好地映射到很多领域,但我无法弄清楚它可能不擅长什么。 那么它有什么不好的(除了需要实时/无 gc 性能的东西)? 最佳答案 我同意你的一般评估,即 Prolo
我正在组装一个简单的元解释器,它输出证明的步骤。我无法将证明步骤作为输出参数。我的谓词 explain1 以我想要的详细形式返回证明,但不是作为输出参数。我的谓词 explain2 将证明作为输出参数
hi(g,plus(A,B),int) :- hi(g,A,int),hi(g,B,int),!. 在上面的语句中 '!' 是什么意思?在声明的末尾签名吗? 最佳答案 那是 cut operator
有没有一种简单的方法可以让 prolog 中的查询只返回每个结果一次? 例如我正在尝试类似的东西: deadly(Xn) :- scary(X), Xn is X - 1, Xp is X + 1,
我正在尝试学习 Prolog。这是我使用这种语言的第一步。作为练习,我想编写可以识别一些扑克手牌的程序(同花顺、同花顺、满屋等)。 我正在 Prolog 中寻找良好的卡片表示。我需要有可能检查一张卡片
我刚刚被介绍到 Prolog 并且正在尝试编写一个谓词来查找整数列表的最大值。我需要写一个从头开始比较,另一个从结尾比较。到目前为止,我有: max2([],R). max2([X|Xs], R):-
我试图在Prolog中编写谓词palindrome/1,当且仅当其列表输入包含回文列表时才为true。 例如: ?- palindrome([1,2,3,4,5,4,3,2,1]). 是真的。 有什么
我正在尝试编写一个程序,该程序将两个列表作为输入并检查适当的子集。我开始于: proper([A],[]). proper([],[A]). proper([A|T1],[A|T2]) :- prop
我是 Prolog 的新手,我正在使用 SWI-Prolog v6.6 在 *.pl 中存储断言文件。 :- dynamic fact/2. assert(fact(fact1,fact2)). 使用
我是一名优秀的程序员,十分优秀!