Prolog 运算符“^"(“插入符号")是什么? [英] What is the Prolog operator `^` ("caret")?
问题描述
Prolog 运算符 ^
是什么?
What is the Prolog operator ^
?
查看 Prolog 内置指令op 给出了内置运算符的列表.
Looking at The Prolog Built-in Directive op gives a list of the built-in operators.
我明白了
**
是 求幂/
是 或
**
is exponentiation/
is or
但是 ^
是什么?
当前三个答案中的每一个都很有价值,我学到了一些东西:
Each of the three current answers are of value and I learned something:
- 罗伊的书
- 示例为 false
- 我接受了 CapelliC 的回答,因为它明确了 ^/2 具有多种含义
取决于上下文,这立即消除了我的困惑.
推荐答案
在 Prolog 中,大多数符号可以在句法级别使用未解释",特别是在 op/3
声明之后,任何atom 可以用作运算符.然后,例如,您可以使用 ^/2
作为域特定语言(DSL)的函数构造函数,并根据您的规则指定语义.
In Prolog, most symbols can be used 'uninterpreted', at syntactic level, in particular after an op/3
declaration, any atom can be used as operator. Then you can use, for instance, ^/2
as a function constructor for a domain specific language (a DSL), with a semantic specified from your rules.
是 SWI-Prolog(或更一般地在 ISO Prolog 中),current_op/3
为您提供有关已声明运算符的信息:
Is SWI-Prolog (or more generally in ISO Prolog), current_op/3
gives you information about declared operators:
?- current_op(X,Y,^).
X = 200,
Y = xfy.
也就是说,任何实现 setof/3
的 Prolog 在用于装饰 2nd支持>论点.同样,当发生在 is/2
is/2 的 Prolog 都应将 ^/2
解释为求幂> 表达.
That said, any Prolog implementing setof/3
is expected to interpret ^/2
as a quantification specifier, when put to decorate the 2nd argument. As well, any Prolog implementing is/2
is expected to interpret ^/2
as exponentiation, when occurring on the right side of the is/2
expression.
这篇关于Prolog 运算符“^"(“插入符号")是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!