什么是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:
- 这本书的罗伊
- 示例错误
- 我接受CapelliC的回答,因为它清楚表明^/2具有多种含义
视情况而定,这立即消除了我的困惑.
- Roy for the book
- false for the examples
- I accepted the answer by CapelliC because it made clear that ^/2 has multiple meanings
depending on context which instantly cleared up my confusion.
推荐答案
在Prolog中,大多数符号可以在语法级别未解释"使用,尤其是在op/3
声明之后,任何原子都可以用作操作员.然后,您可以使用^/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.
也就是说,在装饰2 nd 参数时,任何实现setof/3
的Prolog都应将^/2
解释为量化说明符.同样,当任何实现is/2
的Prolog出现在is/2
表达式的右侧时,都应该将^/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屋!