What does a hyphen at end of a term mean

2019-07-10 16:57发布

I'm trying to understand the statement and I can't find any thing about the -1/4 at the the end of the object term. I've tried searching but I'm not even sure what to search for.

exists(A,object(B,A,apple,countable,na,eq,1)-1/4).

标签: prolog
1条回答
老娘就宠你
2楼-- · 2019-07-10 17:30

The second argument of exists/2 are two terms in pair notation. One term being object(_A,A,apple,countable,na,eq,1) and the other being the 1/4. You can see this if you try the following query:

   ?- exists(A,X-Y).
X = object(_A,A,apple,countable,na,eq,1),
Y = 1/4

And since the second term is an arithmetic expression, you can evaluate it using is/2:

   ?- exists(A,X-Y), Z is Y.
X = object(_A,A,apple,countable,na,eq,1),
Y = 1/4,
Z = 0.25

The functor (-)/2 is often used to denote pairs. As pointed out by @lurker in the comments, the canonical form is -(X,Y) but since (-)/2 is defined as an infix operator in Prolog, both notations are equivalent. To see that consider the following query:

   ?- X-Y = -(X,Y).

true
查看更多
登录 后发表回答