The operator (^)/2
serves several purposes:
setof/3
, bagof/3
Here it is used to denote the existential variables (set) of a term. Like in
setof(Ch, P^child_of(Ch,P), Chs)
where P
is declared as an existential variable.
As a non-standard side effect to this, many systems have defined it as predicate with the following definition:
_^Goal :- Goal
But then, others do not have such a definition. It is in any case a good idea to avoid to define a predicate (^)/2
.
(^)/2
- power
This is an evaluable functor accessible via (is)/2
and arithmetic comparison like (=:=)/2
and (>)/2
. Also library(clpfd)
uses it with this meaning. In contrast to (**)/2
which always results in a float, 2^2
is an integer - thereby permitting arithmetics with bigints. Just try ?- X is 7^7^7.
to see if your system supports them.
Finally, there are user defined uses for (^)/2
that do not collide with above uses like lambda expressions via library(lambda)
(source).
There are a few general remarks about its use. (^)/2
associates to the right which means that:
(7^7^7) = (7^(7^7))
. It has a very low priority which means that you have to use brackets for arguments with standard operators.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…